Below is a possible approach, which is how you can always model the if in the Maven assembly:
- Use the
buid-helper-maven-plugin and its regex-property target to parse the default value of ${project.version} property and create a new $ {only.when.is.snapshot.used} with a value of true or ${project.version} in case of SNAPSHOT suffix found. - Configure the
maven-source-plugin to fulfill the jar target with a special configuration using the skipSource option and passing it a new (dynamic) ${only.when.is.snapshot.used} property: in case of snapshot it will have value true hence skip the execution, otherwise will have value ${project.version} which will be used as false` and, therefore, do not miss this execution - Configure the same as above for
maven-javadoc-plugin using the skip parameter
A sample of the above approach would be as follows:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.10</version> <executions> <execution> <id>build-helper-regex-is-snapshot-used</id> <phase>validate</phase> <goals> <goal>regex-property</goal> </goals> <configuration> <name>only.when.is.snapshot.used</name> <value>${project.version}</value> <regex>.*-SNAPSHOT</regex> <replacement>true</replacement> <failIfNoMatch>false</failIfNoMatch> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>3.0.1</version> <executions> <execution> <id>create-sources</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> <configuration> <skipSource>${only.when.is.snapshot.used}</skipSource> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.10.4</version> <executions> <execution> <id>create-javadoc</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> <configuration> <skip>${only.when.is.snapshot.used}</skip> </configuration> </execution> </executions> </plugin>
That is, there is no need for profiles, this configuration will be enabled only when the version without SNAPSHOT is used, dynamically and without any additional configuration (command line parameters or something else).
As a side reminder, you can also look at the maven-release-plugin , which will effectively refer to the source and javadoc plugins only when they release without the additional (minor) complexity of the above approach.
Otherwise, you can simply use the default profile coming from the Maven Super POM , which will actually reference the same source plugin and javadoc and can be activated using the performRelease property set to true . That is, in any Maven project, you could call the following:
mvn clean package -DperformRelease=true
or
mvn clean package -Prelease-profile
And you will automatically gain an advantage over the default super-profile, and you have sources and javadoc jars, although this approach should be used as the last option, since the profile may be removed from super-pom in future releases.
source share