Merge pull request #1 from apache/feature/attach-only-optionally
SLING-7299 do not always attach built artifact
diff --git a/src/main/java/org/apache/sling/maven/slingstart/AbstractSlingStartMojo.java b/src/main/java/org/apache/sling/maven/slingstart/AbstractSlingStartMojo.java
index 11c25d1..a5bc9ab 100644
--- a/src/main/java/org/apache/sling/maven/slingstart/AbstractSlingStartMojo.java
+++ b/src/main/java/org/apache/sling/maven/slingstart/AbstractSlingStartMojo.java
@@ -142,4 +142,5 @@
protected File getStandaloneOutputDirectory() {
return new File(this.getTmpDir(), "standalone");
}
+
}
diff --git a/src/main/java/org/apache/sling/maven/slingstart/PackageMojo.java b/src/main/java/org/apache/sling/maven/slingstart/PackageMojo.java
index 6a88ef8..9aeed02 100644
--- a/src/main/java/org/apache/sling/maven/slingstart/PackageMojo.java
+++ b/src/main/java/org/apache/sling/maven/slingstart/PackageMojo.java
@@ -30,6 +30,7 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.archiver.jar.JarArchiver;
/**
@@ -51,6 +52,13 @@
*/
@Parameter(defaultValue="false")
protected boolean createWebapp;
+
+ /**
+ * If set to {@code true} does not attach the generated artifact to Maven.
+ * This setting does only apply if the packaging of the current Maven project is not "slingstart".
+ */
+ @Parameter(defaultValue="true")
+ protected boolean attachArtifact;
/**
* The Jar archiver.
@@ -92,7 +100,11 @@
if ( BuildConstants.PACKAGING_SLINGSTART.equals(project.getPackaging()) ) {
project.getArtifact().setFile(outputFile);
} else {
- projectHelper.attachArtifact(project, BuildConstants.TYPE_JAR, BuildConstants.CLASSIFIER_APP, outputFile);
+ if (!attachArtifact) {
+ this.getLog().info("Do not attach the standalone jar to this Maven project");
+ } else {
+ projectHelper.attachArtifact(project, BuildConstants.TYPE_JAR, BuildConstants.CLASSIFIER_APP, outputFile);
+ }
}
} catch ( final IOException ioe) {
throw new MojoExecutionException("Unable to create standalone jar", ioe);
@@ -120,24 +132,32 @@
helper.createArchive();
- projectHelper.attachArtifact(project, BuildConstants.TYPE_WAR, BuildConstants.CLASSIFIER_WEBAPP, outputFile);
+ if (!attachArtifact) {
+ this.getLog().info("Do not attach the webapp to this Maven project");
+ } else {
+ projectHelper.attachArtifact(project, BuildConstants.TYPE_WAR, BuildConstants.CLASSIFIER_WEBAPP, outputFile);
+ }
}
}
- /**
- *
- * @param extension the extension including the leading dot to be used for the file name.
- * @return the absolute file name of the to be created artifact.
- */
- private File getBuildFile(final String extension) {
- final File buildDirectory = new File(this.project.getBuild().getDirectory());
- final File buildFile;
- if ( BuildConstants.PACKAGING_SLINGSTART.equals(project.getPackaging()) ) {
- buildFile = new File(buildDirectory, this.project.getBuild().getFinalName() + extension);
- } else {
- // make sure this filename does not conflict with any other project artifacts (primary or secondary)
- buildFile = new File(buildDirectory, this.project.getBuild().getFinalName() + ".launchpad" + extension);
- }
- return buildFile;
- }
+ /**
+ *
+ * @param extension the extension including the leading dot to be used for the file name.
+ * @return the absolute file name of the to be created artifact.
+ */
+ private File getBuildFile(final String extension) {
+ final File buildDirectory = new File(this.project.getBuild().getDirectory());
+ final File buildFile;
+ if ( BuildConstants.PACKAGING_SLINGSTART.equals(project.getPackaging()) ) {
+ buildFile = new File(buildDirectory, this.project.getBuild().getFinalName() + extension);
+ } else {
+ buildFile = getNonPrimaryBuildFile(project, extension);
+ }
+ return buildFile;
+ }
+
+ public static File getNonPrimaryBuildFile(final MavenProject project, final String extension) {
+ final File buildDirectory = new File(project.getBuild().getDirectory());
+ return new File(buildDirectory, project.getBuild().getFinalName() + ".launchpad" + extension);
+ }
}
diff --git a/src/main/java/org/apache/sling/maven/slingstart/run/StartMojo.java b/src/main/java/org/apache/sling/maven/slingstart/run/StartMojo.java
index c4912e2..f6e01a1 100644
--- a/src/main/java/org/apache/sling/maven/slingstart/run/StartMojo.java
+++ b/src/main/java/org/apache/sling/maven/slingstart/run/StartMojo.java
@@ -50,6 +50,7 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.sling.maven.slingstart.BuildConstants;
+import org.apache.sling.maven.slingstart.PackageMojo;
/**
* Start one or multiple launchpad instance(s).
@@ -400,7 +401,14 @@
return attachedArtifact.getFile();
}
}
-
+
+ // also check for jars in known target folders (in case the jar has been created in this project's target folder but not attached to the Maven project)
+ File localJarFile = PackageMojo.getNonPrimaryBuildFile(project, ".jar");
+ if (localJarFile.exists()) {
+ getLog().info("Using local launchpad jar being created in predefined directory: '" + localJarFile + "'!");
+ return localJarFile;
+ }
+
// Last chance: use the first declared dependency with type "slingstart"
final Set<Artifact> dependencies = this.project.getDependencyArtifacts();
for (final Artifact dep : dependencies) {