Tech-Today
How to get git build id using maven
There are times when git's build number is important for a release. Specially in development mode, when there are frequent releases. So if we want to append the build number on our page, how do we automate it?
For us to achieve this we will need 2 maven plugins: org.codehaus.mojo:buildnumber-maven-plugin and com.google.code.maven-replacer-plugin:replacer.
And this is how to define these plugins in your war project.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<shortRevisionLength>41</shortRevisionLength>
</configuration>
</plugin>
This plugin, produces buildNumber variable, which can be an id, date or a git build no. We will use the last.
With the following assumptions:
1.) The xhtml pages that we want to process for replacement are inside template folder.
2.) We will replace 2 strings: VERSION_NUMBER and BUILD_NUMBER
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>${project.build.directory}/**/layout/*.xhtml</include>
</includes>
<replacements>
<replacement>
<token>@VERSION_NUMBER@</token>
<value>${project.version}</value>
</replacement>
<replacement>
<token>@BUILD_NUMBER@</token>
<value>[${buildNumber}]</value>
</replacement>
</replacements>
</configuration>
</plugin>
-
How To Package A Java Standalone App Using Maven Assembly
The sample codes below will assemble a zipped package of a java standalone app. Dependencies: maven-jar-plugin - to create the jarmaven-assembly-plugin - to assemble the distribution packagepom.xml<plugin> <groupId>org.apache.maven.plugins</groupId>...
-
How To Generate Wadl Via Maven Plugin
So you've written your web service and would now want to create the wadl for it. Assuming you have your web project in eclipse with maven integrated this is what you have to do: 1.) Add the lines below to your pom, you may want to create it's...
-
A Maven Project That Have Multiple Property Files Via Maven Antrun Plugin
This tutorial will answer several questions (below) within a maven project that has several configuration files (dataset, property, persistence). 1.) How to have multiple persistence, datasource and property files depending on the profile or environment...
-
How To Ignore Maven's Plugin Execution Not Covered By Lifecycle Configuration Warning
There are times when you want to ignore some of maven warnings or errors. To do so, normally we add the ff code in the parent project's pom.xml. For example to ignore liferay's theme-merge and build-thumbnail goal warning. <pluginManagement>...
-
How To Add Pmd Reporting To Maven
Before proceeding to this exercise, you may want to try my tutorial on how to setup a maven project to eclipse: http://czetsuya-tech.blogspot.com/2012/04/how-to-create-modularized-maven-project.html. Assuming you have follow the tutorial above, you should...
Tech-Today