Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing POMs via Maven and inserting build version info

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 ?

like image 570
Brian Agnew Avatar asked Feb 02 '10 09:02

Brian Agnew


People also ask

What is pom in Maven?

What is a POM? A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.

How do I publish to Maven Central?

The first step for publishing to Maven Central is to have a Sonatype account. Follow this guide if you don't have an account. Step number two is to make sure your POM files comply with the rules required for uploading to Maven Central, that is, each POM contains the minimum set of elements that identify and describe the generated artifacts.

What configuration can be specified in the pom?

Some of the configuration that can be specified in the POM are the project dependencies, the plugins or goals that can be executed, the build profiles, and so on. Other information such as the project version, description, developers, mailing lists and such can also be specified. The Super POM is Maven's default POM.

How to generate poms with resolved information for the release plugin?

To generate POMs with resolved information (e.g. version numbers) to check the values that the Release Plugin will use, execute the prepare-with-pom goal. Resolved values will be saved in release-pom.xml.


2 Answers

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.

like image 169
Pascal Thivent Avatar answered Sep 22 '22 15:09

Pascal Thivent


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

like image 40
cetnar Avatar answered Sep 22 '22 15:09

cetnar