Build number and version with TC+Maven

I guess this is something easy to do as there are properties created by TC, but how can I, with Maven 2, use the build properties to create a properties file which will be bundled with my application in order to be used at runtime ?

Furthermore, how can I emulate this behaviour when building from Idea (so build properties are not available) ?

Thx.

9 comments

Hello Cedric,

Not really sure what you mean. Could you give a more specific example?

Anyway, Maven has extension mechanisms to enhance the build process with
custom functionality.
For example, you can write your own Ant-scripted plugin which would create
the file you need on a certain phase of the build.

I guess this is something easy to do as there are properties created
by TC, but how can I, with Maven 2, use the build properties to create
a properties file which will be bundled with my application in order
to be used at runtime ?

Furthermore, how can I emulate this behaviour when building from Idea
(so build properties are not available) ?

Thx.


WBR

--
Sergey Anchipolevsky
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


0

Sure, I would like something similar to what TC does itself. When you open the main TC page, at the bottom, you can read " TeamCity Version 2.1.1(build 4261) ". I suppose that to be able to do that, the build number is automatically set by the TC build agent (Ant ? Maven ?) in some property file which is bundled with the build.

What I would like is to read "2.1.1" from my pom.xml, and 4261 from the property set by TC, and generate a properties file for it, assuming a properties file is the easiest way to achieve it, but if you have better ideas ;)

0

Hello Cedric,

Your idea looks quite reasonable. We use the similar way. But I can't give
you an exact solution since we don't build our projects with Maven.

However I'm sure it isn't very difficult to find an example it in the Net
since this problem is quite common.

At least, you can create your own Maven plugin which will read system property
build.number and Maven's artifact version and store them in a file.

Sure, I would like something similar to what TC does itself. When you
open the main TC page, at the bottom, you can read " TeamCity Version
2.1.1(build 4261) ". I suppose that to be able to do that, the build
number is automatically set by the TC build agent (Ant ? Maven ?) in
some property file which is bundled with the build.

What I would like is to read "2.1.1" from my pom.xml, and 4261 from
the property set by TC, and generate a properties file for it,
assuming a properties file is the easiest way to achieve it, but if
you have better ideas ;)

--
Sergey Anchipolevsky
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


0

Cedric Champeau wrote:

I guess this is something easy to do as there are properties created
by TC, but how can I, with Maven 2, use the build properties to
create a properties file which will be bundled with my application in
order to be used at runtime ?


Have you looked at using the maven build-number plugin?

http://commons.ucalgary.ca/projects/maven-buildnumber-plugin/howto.html

With this you can set your artifacts naming to include such things as:

  • Date / Time

  • Incrementing build number

  • Subversion repository revision


This will work both from IDEA and TeamCity as its at the
maven/build-level and not the CI level.

Mark

0

This plugin does not really do what I would like. I guess I'll create an Ant task for it.

0

Cedric Champeau wrote:

This plugin does not really do what I would like. I guess I'll create an Ant task for it.


Out of curiosity - why an Ant task and not your own maven plugin? I
assume possibly because you know how to write ant tasks and not looked
at maven mojos?

0

That's it. Maybe I could check an eye at mojos ;)

0

Finally made my own mojo. Works like a charm. Thanks !

0

Cedric Champeau wrote:

Finally made my own mojo. Works like a charm. Thanks !


:)

0

Please sign in to leave a comment.