It's all about the answers!

Ask a question

Passing properties to Maven based build


1
1
Jose Miguel Ordax Cassa (2.4k4126100) | asked Jan 15 '13, 6:58 a.m.
Is it possible to use the Properties tab to pass properties to Maven like we can do with Ant?

Currently I am just able to pass properties using JVM arguments field.

Thanks in advance,

    Chemi.

2 answers



permanent link
Victor Campbell (3502618) | answered Apr 02 '13, 10:38 a.m.
edited Apr 02 '13, 10:55 a.m.

We are successfully passing the RTC buildLabel property in our Maven builds.

In the .pom, we define:

<properties>

      <buildNumber>1.0-SNAPSHOT</buildNumber>

</properties>

also

     <version>${buildNumber}</version>

(Note: the "N" in buildNumber tag is a capital "N", it just doesn't display that way)

In the build definition for our release builds, on the "goals" in the Maven tab, we add:

-DbuildNumber=1.0-${buildLabel}

Without the parameter, the developers still run SNAPSHOT buiilds, using 1.0-SNAPSHOT.  Our release builds are created with the RTC build label as: MyBuild-1.0-20130402-1000.jar

What doesn't work for us was adding the property in the Properties section, as this doesn't seem to work like it did running ANT builds.


Comments
Victor Campbell commented Apr 18 '13, 2:43 p.m. | edited Apr 18 '13, 2:44 p.m.

The above solution is a simplistic approach to include the RTC buildLabel in Maven builds. For our larger projects that use an aggregate POM with several sub-projects, it doesn't work.

Ideally, the versions plugin would be used to set the version number in all the POMs. An issue with including a call to the plugin within the goals of an RTC Maven build definition is that even though all the POMs physically get updated correctly, a single invocation of Maven does not pick up the changes.

This has required us to substitute the usage of the Maven build definition with a Command Line build definition, which allows us to run a batch file that invokes Maven twice, first with "mvn versions:set", and secondly with "mvn deploy".


permanent link
Nick Edgar (6.5k711) | answered Apr 13 '13, 1:44 p.m.
JAZZ DEVELOPER
Unfortunately, mvn doesn't have a command line option for passing a properties file (which is the mechanism JBE uses to pass properties to Ant), and the Maven participant in JBE does not generate -D's for every property.
You'll need to add these yourself, like in Victor's approach.  It will do property substitution in the various fields of the build definition before invoking mvn.  e.g. to pass through the build label, you can add: -DbuildLabel=${buildLabel}

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.