Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Tuesday, March 22, 2011

Maven auto increment build number

Recently I have been working on auto incrementing build number and generating build artefact name containing build number for application build with maven. Here is how it was done.

In the pom.xml file add following plugin:

<plugins>
         <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0-beta-4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>true</doCheck>
<doUpdate>false</doUpdate>
<format>${version}.{0,number}</format>
<items>
<item>buildNumber</item>
</items>
</configuration>
</plugin>

Now the $buildNumber value can be used from inside the pom file e.g. this way:


<build>
<finalName>
${project.artifactId}-${buildNumber}
</finalName>



Every time build gets to the maven validate phase, there is a buildNumber.properties file created or updated with current build number. However there is a catch.

This solution is good if the buildNumber.properties file is not being moved or deleted  and I have learned that if the file is gone, the build number will be reset to 1 again, making this not usable, especially on dynamically created build agents, as it is used in my organization (Teamcity and Amazon EC2 integration).

More information about the build number plugin: http://mojo.codehaus.org/buildnumber-maven-plugin/

Monday, February 21, 2011

Resolving invalid target release error, java maven build

After running mvn install -DskipTests=true command
I got following error:

[INFO] Scanning for projects...
[INFO] -------------------------------------------------------------------------
---
[INFO] Building visitplanning
[INFO]    task-segment: [install]
[INFO] -------------------------------------------------------------------------
---
[INFO] Ignoring available plugin update: 2.3.2 as it requires Maven version 2.0.
9
[INFO] Ignoring available plugin update: 2.3.1 as it requires Maven version 2.0.
9
[INFO] Ignoring available plugin update: 2.3 as it requires Maven version 2.0.9
[INFO] Ignoring available plugin update: 2.2 as it requires Maven version 2.0.9
[INFO] Ignoring available plugin update: 2.1 as it requires Maven version 2.0.9
[INFO] Ignoring available plugin update: 2.7.2 as it requires Maven version 2.0.
9
[INFO] Ignoring available plugin update: 2.7.1 as it requires Maven version 2.0.
9
[INFO] Ignoring available plugin update: 2.7 as it requires Maven version 2.0.9
[INFO] Ignoring available plugin update: 2.6 as it requires Maven version 2.0.9
[INFO] Ignoring available plugin update: 2.5 as it requires Maven version 2.0.9
[INFO] [resources:resources]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Workspace\XXXXXXXX\src\main\resourc
es
[INFO] [compiler:compile]
[INFO] Compiling 37 source files to D:\Workspace\XXXXXXXX\target\classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
Failure executing javac, but could not parse the error:
javac: invalid target release: 1.6

The solution was pretty simple. Maven uses JAVA_HOME environment variable and by changing it to point to JDK 1.6 the error was resolved.