tags:

views:

298

answers:

2

Hi,

I use maven/hudson to build my project. One of the goals run by hudson is mvn package so I have a full distribution produced on every build. Is there a way (maybe an argument to package?) that I can append the build number to the name of archive that's produced?

thanks,

Jeff

+1  A: 

You can pass an arbitrary property to a Maven build using -D[key]=[value], for example -DbuildNumber=1234 then configure the version in your pom as `1.0.0-${buildNumber}. This approach goes against the general Maven principle though. You'd be better to use Maven's SNAPSHOT processing. SNAPSHOT is a keyword to Maven to update the dependency each time.

You could also use the buildnumber-maven-plugin to automatically add a number to the build version each time. See this answer for some details. The buildnumber plugin can be set to produce a revision based on the SCM revision, a timestamp, or on a sequence.

Rich Seller
thank you for the quick reply.
Jeff Storey
I fixed the reference to the other answer
Rich Seller
As I was reading the first link I realized by the roject version has the name snapshot in it but it doesn't get expanded. In my POM my version is listed as 0.0.1-SNAPSHOT but the zip name (as created by mvn package) is <my-proj-name>-0.0.1-SNAPSHOT-package.zip. Am I not setting it up to be expanded properly?
Jeff Storey
Oh, I misread. I'm not installing or releasing. I'm just including this as part of the Hudson artifacts, so it wouldn't be expanded for that.
Jeff Storey
if you're creating a zip, that implies you're using the assembly plugin and that `package` is the id of the assembly. Is that right? Do you actually want the assembly to be created with a build number?
Rich Seller
Yep. We really just want it for easy referencing purposes so if someone pulls the distribution from hudson and runs into an error they can reference the build number it came from (without trying to go back and remember which one they downloaded it from).
Jeff Storey
+2  A: 

Try the following. It should only activate if the BUILD_NUMBER property is set, so you'll still generate correctly named builds when not using hudson.

<profiles>
    <profile>
        <id>hudson-build</id>
        <activation>
            <property>
                <name>BUILD_NUMBER</name>
            </property>
        </activation>
        <build>
            <finalName>${artifactId}-${version}-${BUILD_NUMBER}</finalName>
        </build>
    </profile>
</profiles>

I'd suggest putting this into a base pom.xml that can then be referenced as a parent to your other pom.xml configs.

For a list of other properties that hudson passes on to maven builds, see http://weblogs.java.net/blog/johnsmart/archive/2008/03/using_hudson_en.html.

Tim Clemons
I ended up going with this solution is at was simpler. Both are very good answers. Thanks.
Jeff Storey