views:

89

answers:

3

Is there a way to specify the artifact version outside of the POM file?

I have 2 CI projects that build an artifact. One builds a "stable" development version from a 'develop' branch and the other builds an unstable version which is the result of merging all active feature branches into the develop branch. I want the stable version to build as xyz-1.0.jar and the integration build to go in as xyz-1.0-SNAPSHOT.jar. Is there a way for the CI job to run a maven task or specify via the command line if a release or snapshot jar should be built without manually modifying the POM? Currently I have the version specified as 1.0 in the pom. I considered using the release plugin but I don't want the automatic version number increase and tagging that it does.

A: 

You should be able to achieve this using maven profiles

Scobal
A: 

Short answer: no. And here are some additional remarks:

  • It doesn't make much sense to use a "released" version (i.e. non SNAPSHOT) for a branch under CI since released versions are not downloaded again even if a newer version is available.
  • Released versions should be tagged (e.g. 1.0), maintenance is done is in a branch derived from the tag (e.g. 1.0.1-SNAPSHOT).
  • If you want to distinguish versions built from different branches, use different versions in the POMs.
Pascal Thivent
In the maven profile I have the updatePolicy set to always for the development release repo. That should make it always check for newer versions even in the case of a non SNAPSHOT, no?
Adam B
Adam B
@Adam First comment: No, artifacts are not supposed to change after being released. You'd have to manually copy/delete the file. Second comment: Yes, I understand that and I agree with the last sentence. For the first part, that's why the release plugin is handy (it will upgrade the version numbers for you).
Pascal Thivent
Thank you for your help Pascal! Updating the version number is where the problem comes in. If jar A is a dependency of 20 other apps/jars then I have to find and update those poms to the new jar A version. I think the versions plugin can help with the updating part, but what about the finding part? The other question then is what version gets used for the integration build? Depending on when feature branches are created there could be a conflict on the version in the pom. Since the build is done via CI I cannot manually resolve the conflict. Perhaps this justifies its own topic.
Adam B
@AdamB: Indeed, the version plugin can help to update versions once you *found* them. But it doesn't solve the finding part. Now, back to your initial question, I'd keep the 1.0-SNAPSHOT for the stable development version and use something like 1.0-work-SNAPSHOT for the work branch. Your 60 modules don't need to depend on this version after all.
Pascal Thivent
A: 

I was able to accomplish this by using a property in my POM and then overriding it via the command line.

pom.xml:

 ...
    <version>${artifactVersion}</version>
    <properties>
       <artifactVersion>1.0</artifactVersion>  <!-- default version -->
    </properties>
    ...

Then overriding with mvn -DartifactVersion=1.0-SNAPSHOT package

But Pascal's answer above is more in line with what I was really asking. My solution is more of a workaround I feel.

Adam B
I'm not sure this will work with inheritance (and that's why I didn't suggest it).
Pascal Thivent