4

I am working on an initiative to auto increment the X.Y.Z version during the build process. In this case we are not removing the SNAPSHOT suffix (to make it a released version), rather increasing the minor part of the version:

  • X.Y.Z-SNAPSHOT => X.Y.Z+1-SNAPSHOT
  • NOT X.Y.Z-SNAPSHOT => X.Y.Z

I cannot use the maven release plugin since it is ONLY capable of cutting off SNAPSHOT suffix to make it released versions. So, I ended up creating a custom script which has the logic to increment versions.

My question here is how can I best implement the following steps:

  1. Check out the pom.xml from perforce.
  2. Run the custom script to increment version.
  3. Commit the pom.xml change if deployment was successful.

I created a maven profile autoversion which partially meets the above needs. Maven first increments the version as part of generate resources phase. However, it ends up deploying the older version of the project.

mvn -Pautoversion clean deploy

         <profile>
        <id>autoversion</id>
        <build>
            <plugins>
                                    <plugin>
                                      <artifactId>exec-maven-plugin</artifactId>
                                      <groupId>org.codehaus.mojo</groupId>
                                      <executions>
                                            <execution>
                                              <id>Calculate version</id>
                                              <phase>generate-resources</phase>
                                              <goals>
                                                    <goal>exec</goal>
                                              </goals>
                                              <configuration>
                                                    <executable>${basedir}/autoincrementversion.sh</executable>
                                                    <arguments>
                                                            <argument>-bdj</argument>
                                                    </arguments>
                                              </configuration>
                                            </execution>
                                      </executions>
                                    </plugin>
                                    <plugin>
                                            <groupId>org.apache.maven.plugins</groupId>
                                            <artifactId>maven-scm-plugin</artifactId>
                                            <version>1.9</version>
                                            <executions>
                                                    <execution>
                                                            <phase>generate-resources</phase>
                                                            <goals>
                                                                    <goal>edit</goal>
                                                                    <goal>checkin</goal>
                                                            </goals>
                                                            <configuration>
                                                                    <username>jenkins</username>
                                                                    <basedir>./</basedir>
                                                                    <includes>pom.xml</includes>
                                                                    <message>Auto increment pom version</message>
                                                            </configuration>
                                                    </execution>
                                            </executions>
                                    </plugin>
            </plugins>
        </build>
    </profile>


[INFO] ------------------------------------------------------------------------
[INFO] Building project 99.22.8
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- versions-maven-plugin:1.3.1:set (default-cli) @ project ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: /opt/project/auto-increment-release
[INFO] Processing com.project
[INFO]     Updating project com.project
[INFO]         from version 99.22.8 to 99.22.9
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.135s
[INFO] Finished at: Wed Nov 05 23:15:13 PST 2014
[INFO] Final Memory: 11M/152M
[INFO] ------------------------------------------------------------------------

Any pointers to achieve the requirement is highly appreciated.

Ajean
  • 5,528
  • 14
  • 46
  • 69
Ganga
  • 883
  • 12
  • 24
  • I would say you should take a deep look into [Maven 3.2.1](http://maven.apache.org/docs/3.2.1/release-notes.html) there is support directly from outsite via properties. See release notes `Continuous delivery friendly versions`. – khmarbaise Nov 06 '14 at 20:41
  • Thanks for the pointer, good to know, but upgrade is not an immediate option now since we have to test various other factors. – Ganga Nov 06 '14 at 23:18
  • @user6930, I'm not sure you are correct in this part that Maven Release Plugin is _"ONLY capable of cutting off SNAPSHOT suffix to make it released versions"_. It actually proposes to auto-increment the smallest significant number of the version. Isn't it what you want? – uvsmtid Jul 22 '15 at 17:00

1 Answers1

1

We are considering to actually use Maven Release Plugin (MRP) in similar situation changing ALL version numbers to something like X.Y.Z.N:

  • X.Y.Z is semantic part which changes rarely during proper human-guided release
  • N is incremental part (meaningless except sequence ordering) which MRP is able to increment automatically

Yes, MRP will create two additional commits (with released version and next SNAPSHOT version), but... If your developers make snapshot builds they need X.Y.Z.N-SNAPSHOT versions. And if you want incremental release, you also need X.Y.Z.N too. Hence, the same two commits.

All you may avoid optionally is X.Y.Z.N tagging waiting for X.Y.Z only.

Community
  • 1
  • 1
uvsmtid
  • 4,187
  • 4
  • 38
  • 64