12

While development we use the SNAPSHOT version (for example 1.0-SNAPSHOT) for maven modules.

For example Parent Module's Maven Configugration:

<groupId>com.mycomp.basemodule</groupId>
<artifactId>base-module</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>base-module</name>
<modules>       
    <module>sub-module1</module>        
    <module>sub-module2</module>        
    <module>sub-module3</module>        
    <module>sub-module4</module>        

</modules>

For example Child Module's Maven Configugration:

Sub-Module-1:

<parent>
     <groupId>com.mycomp.basemodule</groupId>
      <artifactId>base-module</artifactId>
      <version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.mycomp.sub-module1</groupId>
<artifactId>sub-module1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>sub-module1</name>

Also consider same configuration for other sub modules (2,3,4) too.

While releasing the project/patch, we need to change this SNAPSHOT version to actual release version.

There is one crude way to change the version. I can go to each and every pom.xml for parent and all child modules and can change the SNAPSHOT version to release version.

Is there any other best practice to change this SNAPSHOT version to release version at common place so that I don't need to update all pom.xml files?

Narendra Verma
  • 2,372
  • 6
  • 34
  • 61

2 Answers2

11

I believe, you should use maven-release plugin to solve the problem in the way it has been intended in maven. See: http://maven.apache.org/guides/mini/guide-releasing.html

As docs say:

The main aim of the maven-release plugin is to provide a standard mechanism to release project artifacts outside the immediate development team. The plugin provides basic functionality to create a release and to update the project's SCM accordingly.

UPDATE: seems you're not the first one having the question, see: Maven versioning best practices Answer seem to be quite complete there.

Community
  • 1
  • 1
Peter Butkovic
  • 11,143
  • 10
  • 57
  • 81
  • Thanks Peter for your reply. But, it seems like that maven-release-plugin increment version automatically while we do the release? What if I want version increment by my own? – Narendra Verma Jan 31 '13 at 07:03
  • I think, I don't see the point here. what is the difference in result when comparing your expectation with what release plugin provides you? – Peter Butkovic Jan 31 '13 at 08:17
  • @NarendraVerma What might be the reason for doing increment yourself than doing it automatically by maven-release-plugin? If you like having anything different than maven-release-plugin would suggest you can use some command line options to influence it's behaviour. – khmarbaise Jan 31 '13 at 14:54
  • 3
    @Khmarbaise: Let say currently we have 1.5-SNAPSHOT version in development. While releasing the application, if I use maven-release-plugin, it will release code as 1.5 and convert my development environment to **1.6-SNAPSHOT**. What If I want my development version **1.5.1-SNAPSHOT** instead of **1.6-SNAPSHOT**? – Narendra Verma Feb 01 '13 at 09:34
  • @NarendraVerma Does this answer help: http://stackoverflow.com/questions/5557659/using-maven-release-plugin-autoversionsubmodules-to-increment-major-version ? – Peter Butkovic Feb 01 '13 at 16:27
4

The simplier way: update the version with maven-version-plugin then prepare release in your own way.

Radio Rogal
  • 462
  • 4
  • 9
  • simpler arguably, but not the "convention over configuration" approach maven projects should use. – Eddie Feb 12 '14 at 18:41
  • 2
    "Convetion over configuration" are implemented by POM, not Release Plugin. Version plugin is true Maven plugin too. Not all people like Release plugin and they use own way to release a product: [Lieven Doclo, Why I Never Use the Maven Release Plugin](http://java.dzone.com/articles/why-i-never-use-maven-release "JavaLobby article") – Radio Rogal Feb 13 '14 at 11:07