The Lazy Dev

Do less. Develop more.  
Filed under

maven release plugin

 

No pain releases with Maven

Maven Release Plugin is the sort of thing that can strikes fear into people. What is that thing going to do with my project?
Well, I gave the guy a try yesterday and after some problem (I did follow website documentation, me fool) I realize that is really fine and is a great help.

First: the configuration. Nothing is needed. This is nice. You just need a maven project with normally is in development, let's say our version number is 1.0.0-SNAPSHOT. This is a Maven convention: version-SNAPSHOT.
Do not trust Maven web site that says to configure a tagBase parameter. That line created me a lot of problems and is not needed at all.

Second: preparation. Run

mvn release:prepare

And wait. Maven will ask you
1. what will be the version number for the project (and all it's submodules, if any), suggesting 1.0.0
2 what is the TAG name on subversion, suggesting artifactId-1.0.0
3. what is the new development version number, suggesting 1.0.1-SNAPSHOT.
For all these questions, you normally will just accept defaults.
Finally, all the tests are run.

If everything was all right, we have a new tag/my-app-1.0.0 on the subversion server and the project is ready to be released, version number locally are changed accordingly. We now can perform the release.

mvn release:perform

Here the default Maven target is run (deploy deploy-site, if you did not configured differently). In the end, we have our 1.0.0 deployed on the articfact repository and the new local version number is 1.0.1-SNAPSHOT.

The release is complete and we can continue.
If something is wrong during preparation, we can just run

mvn release:rollback

Is very nice and painless process. Things are as easy as this with multi modules projects, but we have to take care that modules are already configured the right way. That is:

Parent project

   <groupId>myGroup</groupId>
   <artifactId>myArtifact</artifactId>
   <version>1.0.0-SNAPSHOT</version>
   <packaging>pom</packaging>
 

A module:

   <parent>
      <groupId>myGroup</groupId>
      <artifactId>myArtifact</artifactId>
      <version>1.0.0-SNAPSHOT</version>
   </parent>

   <artifactId>module1</artifactId>
 


Without adding non useful information about group and version in the module.

Module Dependencies. Better to use this form

      <dependency>
         <groupId>myGroup</groupId>
          <artifactId>module1</artifactId>
         <version>${pom.version}</version>
       </dependency>
 

this way, we specify the version only in the parent POM and in the parent definition of all modules. Maven Release plugin will change all those version number accordingly.

Filed under  //   maven release plugin  

Comments [0]