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
?
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.
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.
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.
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.
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.
Try to use generateReleasePoms property of maven-realease-plugin, maybe that helps a little.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With