I want to be able to auto-increment a java project's release version by using non-interactive mode in Maven release plugin (mvn -B release:prepare
). However I do not want to use the default Maven versioning schema.
The schema that I would like to use is <major>.<minor>.<bugfix>-SNAPSHOT
. I did manage to do this inside the pom file, however Maven tries to increment it as follows:
1.0.0-SNAPSHOT
1.0.1-SNAPSHOT
1.0.2-SNAPSHOT
...
However I want to be able to have control on this and while some of the time I do have bugfixes and the above incrementing works, most of the times I would like to release minor releases and therefore an increment that looks like this:
1.0.0-SNAPSHOT
1.1.0-SNAPSHOT
1.2.0-SNAPSHOT
...
Setting the Maven versionAdd an environment variable to your development system called ATLAS_MVN. Set the value of ATLAS_MVN to your Maven executable. Keep in mind this should be the Maven executable, not the Maven home. Verify the configuration by running the atlas-version command.
The Versions Maven Plugin is a Maven plugin which provides you the information of which libraries could be updated.
The plugin will extract file revisions associated with the current release. Maven will compile, test and package the versioned project source code into an artifact. The final deliverable will then be released into an appropriate maven repository.
You can handle this via build-helper-maven-plugin like this:
mvn build-helper:parse-version versions:set \
release:prepare \
-DdevelopmentVersion =\${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}.0-SNAPSHOT \
release:perform
This will set the 1.1.0-SNAPSHOT
as next development version..The next time you call release plugin it will make 1.1.0
from it and will automatically increment 1.1.1-SNAPSHOT
if you don't like just use the call above...
"The maven way"is to follow maven rules, or to create a custom plugin. Maven plays nice as long as you want to do what it expects that you want to do. Maybe solution for you would be to use just "1.1" most of the cases, and if you want to do a bugfix release, then to add 3rd number by hand.
However if you really wish to fight against maven, there is a possibility to setup properties from within some other plugin.. i.e. like this:
<profile>
<id>customversionnumber</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<executions>
<execution>
<id>set-release-version</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
project.properties.setProperty("releaseVersion","1.3.0")
System.out.println("releaseVersion set to 1.3.0")
</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Then, you'd invoke release plugin like this
mvn -Pcustomversionnumber initialize release:prepare
.
And it will release it as "1.3.0" regardless whats in 'version' tag. I'll have to code that number increment on your own of course.
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