views:

332

answers:

2

I'm building Maven projects via TeamCity/Git and trying to insert the TeamCity build numbers in the pom.xml that gets published to my repository upon a successful build. Unfortunately I can't determine how to publish a pom.xml with the substitutions inserted.

My pom.xml contains info like:

<version>${build.number}</version>

where build.number is provided by TeamCity. That all builds ok, and if (say) build.number = 0.1, then the deployment is a pom.xml to a directory with 0.1. All well and good.

However, the pom.xml that is deployed is the pom.xml without the substitutions made. i.e. Maven is running with a pom.xml with appropriate substitutions, but deploys the initial version and so I get

<version>${build.number}</version>

in the final pom.xml. How can I get the build version number in the pom.xml ?

+2  A: 

I wouldn't use this approach because it makes building a project checked out from the SCM not possible without providing the build.number property. I don't think that this is a good thing. Maybe I'm missing something though.

Actually, I don't get what you are trying to achieve exactly (why don't you write the build number in the manifest for example). But, according to the Maven Features on the Teamcity website:

By default, it also keeps TeamCity build number in sync with the Maven version number (...).

Couldn't that be helpful? There is another thread about this here.

Pascal Thivent
I can build a project checked out by providing a default profile with a build.number of 'NONE' (or similar), and my TeamCity build uses a different profile that uses the TeamCity property. Does that address your first concern.My core build is deploying a pom.xml alone. I'd like to change that, then get TeamCity to build/deploy to a new build number and change the version *within* the deployed pom.xml. Does that make sense ? I'll check out that link, though.
Brian Agnew
@Brian While I like the SNAPSHOT mechanism (but that's another story), the profile trick will work for the first point. Regarding the second point, I'm not sure to get everything. I usually use the release plugin to change the version, create a branch, etc. I'll think about this.
Pascal Thivent
@Pascal - thx. My Maven knowledge is strictly limited.
Brian Agnew
@Pascal Good answer. Brain, it looks as if you try to work just in the opposite direction. The Maven pom should provide the version number for your product (as it is planned for releasing). Use the release-plug-in to create the (final) release (so without SNAPSHOT). TeamCity can add a build-number somewhere (in logging and in the created jar MANIFEST.MF). But it should not be used as the version number for your product.
Verhagen
A: 

Try to use generateReleasePoms property of maven-realease-plugin, maybe that helps a little.

cetnar