Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Release Plugin auto increment custom format version

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
...
like image 203
James Avatar asked Jul 11 '18 13:07

James


People also ask

How do I change my Maven version?

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.

What is versions Maven plugin?

The Versions Maven Plugin is a Maven plugin which provides you the information of which libraries could be updated.

How does Maven release plugin work?

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.


2 Answers

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...

like image 112
khmarbaise Avatar answered Nov 06 '22 17:11

khmarbaise


"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.

like image 30
Martin Špelina Avatar answered Nov 06 '22 16:11

Martin Špelina