main
  1<!DOCTYPE html>
  2
  3<html lang="fr">
  4  
  5  <head>
  6    <meta charset="utf-8">
  7    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  8
  9    <link rel="start" href="https://vincent.demeester.fr" />
 10
 11    <title>Vincent Demeester</title>
 12    <link rel="canonical" href="https://vincent.demeester.fr/posts/2012-07-23-maven-release-gitflow/">
 13    <link href="https://vincent.demeester.fr/index.xml" rel="alternate" type="application/rss+xml" title="Vincent Demeester" />
 14
 15    <link rel="openid.server" href="https://indieauth.com/openid" />
 16    <link rel="openid.delegate" href="http://vincent.demeester.fr/" />
 17    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
 18
 19    <link rel="stylesheet" href="/css/screen.css" type="text/css" />
 20    <link rel="stylesheet" href="/css/sbrain.css" type="text/css" />
 21    <link rel="stylesheet" href="/css/syntax.css" type="text/css" />
 22
 23  </head>
 24  
 25  <body lang="fr" class="gray">
 26    
 27
 28
 29
 30
 31
 32<div id="main-container">
 33  <div id="page">
 34    <article class="post">
 35      <header>
 36        <h1 class="emphnext">Maven Release Gitflow</h1><a href='https://vincent.demeester.fr/posts/2012-07-23-maven-release-gitflow/'></a>
 37        <address class="signature">
 38          <span class="date">Mon, 23 July, 2012</span>
 39          <span class="words">(400 Words)</span>
 40        </address>
 41	<ul class="tag_box inline">
 42	  
 43	  <li class="category"><a href="/categories/#developement">developement</a></li>
 44	  
 45	  
 46	  
 47	  
 48	  
 49	  <li class="tag tag-maven"><a href="/tags/#maven">maven<span>2</span></a></li>
 50	  
 51	  
 52	  <li class="tag tag-java"><a href="/tags/#java">java<span>4</span></a></li>
 53	  
 54	  
 55	  <li class="tag tag-git"><a href="/tags/#git">git<span>3</span></a></li>
 56	  
 57	  
 58	  <li class="tag tag-gitflow"><a href="/tags/#gitflow">gitflow<span>1</span></a></li>
 59	  
 60	  
 61	  <li class="tag tag-release"><a href="/tags/#release">release<span>1</span></a></li>
 62	  
 63	  <br/>
 64	  
 65	</ul>
 66      </header>
 67      
 68      
 69      
 70      
 71
 72<p>I like a lot the <a href="http://nvie.com/posts/a-successful-git-branching-model/">gitflow</a> way of managing project.
 73When working on maven project, there is few great plugins that helps to get
 74the work done. One of them is <a href="http://maven.apache.org/plugins/maven-release-plugin">maven-release-plugin</a>.</p>
 75
 76<p>Inspired on this <a href="https://gist.github.com/1043970">gist</a>, I&rsquo;ve come with
 77a cool way of doing things (let say we want to release a 0.1 version of an
 78artifact) :</p>
 79
 80<h1 id="prepare-the-pom-xml">Prepare the pom.xml.</h1>
 81
 82<p>It needs <code>&lt;scm&gt;</code> entries, <code>&lt;distributionManagement&gt;</code> entries
 83(to know where to deploy the release artifact) and few options for the
 84maven-release-plugin :</p>
 85
 86<div class="highlight"><pre class="chroma"><code class="language-xml" data-lang="xml"><span class="nt">&lt;project&gt;</span>
 87
 88    <span class="c">&lt;!-- […] --&gt;</span>
 89    <span class="nt">&lt;build&gt;</span>
 90        <span class="nt">&lt;plugins&gt;</span>
 91            <span class="c">&lt;!-- […] --&gt;</span>
 92            <span class="nt">&lt;plugin&gt;</span>
 93                <span class="nt">&lt;groupId&gt;</span>org.apache.maven.plugins<span class="nt">&lt;/groupId&gt;</span>
 94                <span class="nt">&lt;artifactId&gt;</span>maven-release-plugin<span class="nt">&lt;/artifactId&gt;</span>
 95                <span class="nt">&lt;version&gt;</span>2.3.2<span class="nt">&lt;/version&gt;</span>
 96                <span class="nt">&lt;configuration&gt;</span>
 97                    <span class="nt">&lt;tagNameFormat&gt;</span>v@{project.version}<span class="nt">&lt;/tagNameFormat&gt;</span>
 98                    <span class="nt">&lt;pushChanges&gt;</span>false<span class="nt">&lt;/pushChanges&gt;</span>
 99                    <span class="nt">&lt;localCheckout&gt;</span>true<span class="nt">&lt;/localCheckout&gt;</span>
100                <span class="nt">&lt;/configuration&gt;</span>
101            <span class="nt">&lt;/plugin&gt;</span>
102            <span class="c">&lt;!-- […] --&gt;</span>
103        <span class="nt">&lt;/plugins&gt;</span>
104    <span class="nt">&lt;/build&gt;</span>
105    <span class="c">&lt;!-- […] --&gt;</span>
106
107<span class="nt">&lt;/project&gt;</span></code></pre></div>
108
109<p>Few explanation here :</p>
110
111<ul>
112<li><code>tagNameFormat</code> is here to change the default tag name (which is <code>${project.artifactId}-${project.version}</code>) to a better one.</li>
113<li><code>pushChanges</code> set to <code>false</code> tells  maven-release-plugin not to push
114changes (this will become useful)</li>
115<li><code>localCheckout</code> set to <code>true</code> tells maven-release-plugin to clone from
116local repository (not distant). This is especially useful here because we
117didn&rsquo;t push anything (so not setting this option would result in a failure).</li>
118</ul>
119
120<h1 id="the-real-stuff">The real stuff</h1>
121
122<p>First create a release branch from develop.</p>
123
124<div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">$ git checkout -b release/v0.1 develop</code></pre></div>
125
126<p>Then run the maven release stuff.</p>
127
128<div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">$ mvn release:prepare               <span class="c1"># change the pom, commit and tag version, and</span>
129                                    <span class="c1"># re-change pom (by incrementing SNAPSHOT version)</span>
130$ mvn release:perform               <span class="c1"># get the tagged version, compile and deploy</span></code></pre></div>
131
132<p>And the real fun begins.</p>
133
134<div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">$ git checkout develop              <span class="c1"># get back to the develop branch</span>
135$ git merge --no-ff release/v0.1    <span class="c1"># merge the version back into develop</span>
136$ git checkout master               <span class="c1"># go to the master branch</span>
137$ git merge --no-ff release/v0.1~1  <span class="c1"># merge the version back into master but</span>
138                                    <span class="c1"># the tagged version instead of the release/v0.1 HEAD</span>
139$ git branch -D release/v0.1        <span class="c1"># Removing the release branch</span>
140$ git push --all <span class="o">&amp;&amp;</span> git push --tags <span class="c1"># Finally push everything</span></code></pre></div>
141
142<p>The real magic here is the <code>git merge --no-ff release/v0.1~1</code> which will
143merge into master the commit before the HEAD of the branch <code>release/v0.1</code>.</p>
144
145<p>The next step would be to create a helper script that automates this and
146verify that the <code>pom.xml</code> has the right configuration options.</p>
147
148<p><strong>Edit 17:58</strong> : You can take a look <a href="https://github.com/vdemeester/java-config/blob/master/bin/mvn-release-flow">here</a></p>
149
150      
151    </article>
152    <hr />
153    <div class="prev-next">
154      
155      <a class="paging-link prev" href="/posts/2012-12-16-gollum-comme-wiki-personnel/" title="Gollum Comme Wiki Personnel">← Previous post</a>
156      
157
158      
159      <a class="paging-link next" href="/posts/2012-07-21-news/" title="News">Next post →</a>
160      
161    </div>
162
163  </div>
164</div>
165
166<footer>
167  <nav>
168    
169    <a href="/">home</a>
170    <span class="text-muted"> | </span>
171    
172    <a href="/about">about</a>
173    <span class="text-muted"> | </span>
174    
175    <a href="/archive">archive</a>
176    <span class="text-muted"> | </span>
177    
178    <a href="/categories">categories</a>
179    <span class="text-muted"> | </span>
180    
181    <a href="/tags">tags</a>
182    <span class="text-muted"> | </span>
183    
184    <a href="https://twitter.com/vdemeest">twitter</a>
185    <span class="text-muted"> | </span>
186    
187    <a href="https://github.com/vdemeester">github</a>
188    <span class="text-muted"> | </span>
189    
190    <a href="https://vincent.demeester.fr/index.xml">rss</a>
191  </nav>
192  <br/>
193  <address>
194    <span class="copyright">
195      Content and design by Vincent Demeester
196      (<a rel="licence" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Some rights reserved</a>)
197    </span><br />
198    <span class="engine">
199      Powered by <a href="https://gohugo.io/">Hugo</a> and <a href="https://github.com/kaushalmodi/ox-hugo/">ox-hugo</a>
200    </span>
201  </address>
202</footer>
203</body>
204