This would be really useful to avoid storing passwords in pom.
Many Thanks
What is a Mojo? A mojo is a Maven plain Old Java Object. Each mojo is an executable goal in Maven, and a plugin is a distribution of one or more related mojos.
To refer to environment variables from the pom. xml, we can use the ${env. VARIABLE_NAME} syntax. We should remember to pass the Java version information via environment variables.
From Maven documentation: pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one.
groupId – a unique base name of the company or group that created the project. artifactId – a unique name of the project. version – a version of the project.
You can catch a user input using maven-antrun-plugin. The following example show how ask current user the new project version.
<profile>
<id>change-version</id>
<build>
<defaultGoal>validate</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>catch-new-version</id>
<goals>
<goal>run</goal>
</goals>
<phase>validate</phase>
<configuration>
<target>
<!-- == catch new version in a prompt == -->
<input
message="Please enter the new SNAPSHOT version (current is '${project.version}'): "
addproperty="new-user-version" />
</target>
<exportAntProperties>true</exportAntProperties>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.8.4</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>set-new-version</id>
<goals>
<goal>set</goal>
</goals>
<phase>validate</phase>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
<newVersion>${new-user-version}</newVersion>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
You can run this feature by calling :
mvn -N -P change-version
Some explanations :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With