home

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

2012-07-23-maven-release-gitflow.org (3473B)


      1 #+title: Maven Release Gitflow
      2 #+date: <2012-07-23 Mon>
      3 #+filetags: maven java git gitflow release
      4 #+setupfile: ../templates/post.org
      5 
      6 * Introduction
      7 
      8 I like a lot the [[http://nvie.com/posts/a-successful-git-branching-model/][gitflow]] way of managing project. When working on maven project, there is
      9 few great plugins that helps to get the work done. One of them is [[http://maven.apache.org/plugins/maven-release-plugin][maven-release-plugin]].
     10 
     11 Inspired on this [[https://gist.github.com/1043970][gist]], I've come
     12 with a cool way of doing things (let say we want to release a 0.1
     13 version of an artifact) :
     14 
     15 * Prepare the pom.xml.
     16   :PROPERTIES:
     17   :CUSTOM_ID: prepare-the-pom.xml.
     18   :END:
     19 
     20 It needs =<scm>= entries, =<distributionManagement>= entries (to know
     21 where to deploy the release artifact) and few options for the
     22 maven-release-plugin :
     23 
     24 {{< highlight xml >}}
     25 #+begin_src xml
     26 <project>
     27 
     28     <!-- […] -->
     29     <build>
     30         <plugins>
     31             <!-- […] -->
     32             <plugin>
     33                 <groupId>org.apache.maven.plugins</groupId>
     34                 <artifactId>maven-release-plugin</artifactId>
     35                 <version>2.3.2</version>
     36                 <configuration>
     37                     <tagNameFormat>v@{project.version}</tagNameFormat>
     38                     <pushChanges>false</pushChanges>
     39                     <localCheckout>true</localCheckout>
     40                 </configuration>
     41             </plugin>
     42             <!-- […] -->
     43         </plugins>
     44     </build>
     45     <!-- […] -->
     46 
     47 </project>
     48 #+end_src
     49 
     50 Few explanation here :
     51 
     52 - =tagNameFormat= is here to change the default tag name (which is
     53   =${project.artifactId}-${project.version}=) to a better one.
     54 - =pushChanges= set to =false= tells maven-release-plugin not to push
     55   changes (this will become useful)
     56 - =localCheckout= set to =true= tells maven-release-plugin to clone from
     57   local repository (not distant). This is especially useful here because
     58   we didn't push anything (so not setting this option would result in a
     59   failure).
     60 
     61 * The real stuff
     62   :PROPERTIES:
     63   :CUSTOM_ID: the-real-stuff
     64   :END:
     65 
     66 First create a release branch from develop.
     67 
     68 #+begin_src bash
     69 $ git checkout -b release/v0.1 develop
     70 #+end_src
     71 
     72 Then run the maven release stuff.
     73 
     74 #+begin_src bash
     75 $ mvn release:prepare               # change the pom, commit and tag version, and
     76                                     # re-change pom (by incrementing SNAPSHOT version)
     77 $ mvn release:perform               # get the tagged version, compile and deploy
     78 #+end_src
     79 
     80 And the real fun begins.
     81 
     82 #+begin_src bash
     83 $ git checkout develop              # get back to the develop branch
     84 $ git merge --no-ff release/v0.1    # merge the version back into develop
     85 $ git checkout master               # go to the master branch
     86 $ git merge --no-ff release/v0.1~1  # merge the version back into master but
     87                                     # the tagged version instead of the release/v0.1 HEAD
     88 $ git branch -D release/v0.1        # Removing the release branch
     89 $ git push --all && git push --tags # Finally push everything
     90 #+end_src
     91 
     92 The real magic here is the =git merge --no-ff release/v0.1~1= which will
     93 merge into master the commit before the HEAD of the branch
     94 =release/v0.1=.
     95 
     96 The next step would be to create a helper script that automates this and
     97 verify that the =pom.xml= has the right configuration options.
     98 
     99 *Edit 17:58* : You can take a look [[https://github.com/vdemeester/java-config/blob/master/bin/mvn-release-flow][here]]