mico mico - 8 days ago 8
Java Question

How to make maven build take version from constant

I have a multi module project. I have introduced a property

app.version
which I use instead of version everywhere in the pom.xml: in version tag and in dependencies in modules part.

I use maven 3.1.1 in Hudson environment.

After substituting written values (1.6.0-SNAPSHOT) with
${app.version}
, the build order that really goes through without error, is gone.

What caused the issue?

I got these kind of warnings in the begin, may it affect?

[WARNING] Some problems were encountered while building the effective model for com.mycompany.project:project-module:jar:2.4.0
[WARNING] 'version' contains an expression but should be a constant. @ com.mycompany.project:project-module:${app.version}, /var/lib/hudson/jobs/myJob TRUNK Maven/workspace/project-module/pom.xml, line 20, column 11


I would need to parse too much the pom.xml:s, so the hierarchy is like follows, I give it:

main_pom
|
--- modules
| |
| --- all other modules
--- test |
module A
| |
| module B
module C


I give for hudson to start from main_pom. It handles main_pom as last. Why?
It starts now from random one in all other modules part, builds the others, then modules, test and main_pom. Why this insane order?

The fail is in module A. It builds that first and not module B.

Correct order would be to start from main_pom -> module B -> module A etc but it starts directly from module A.

Edit:

My pom.xmls have the following structure:

<parent>
<groupId>com.mycompany.project</groupId>
<artifactId>modules or parent_pom</artifactId>
<version>${app.version}</version>
<relativePath>../modules or parent_pom</relativePath>
</parent>

<dependency>
<groupId>com.mycompany.project</groupId>
<artifactId>some other module</artifactId>
<version>${app.version}</version>
</dependency>

Answer

Maven 3.2.1 or later is required to cleanly use variables in the main <version> corrdinate of a pom file.