tags:

views:

41

answers:

3

Hi,

I have a parent POM with the following config

<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>1.2-SNAPSHOT</version>

Each child project which inherits from this parent POM, has a config such as the following:

<parent>
    <groupId>com.amadeus.jcp.ui.skinning.skinning-system</groupId>
    <artifactId>parent</artifactId>
    <version>1.2-SNAPSHOT</version>
</parent>

I want all these project version numbers to stay in synch. At the moment, if I change the parent version to 1.3, I then have to go change all the child project versions to 1.3. Is there any way I can avoid duplicating the version numbers in all the child projects?

I tried replacing the above with

<parent>
    <groupId>com.amadeus.jcp.ui.skinning.skinning-system</groupId>
    <artifactId>parent</artifactId>
</parent>

and

<parent>
    <groupId>com.amadeus.jcp.ui.skinning.skinning-system</groupId>
    <artifactId>parent</artifactId>
    <version>${project.version}</version>
</parent>

But neither of these work. I'm using Maven version 2.1.0.

Thanks, Don

A: 

You shouldn't define a version... in the child module, but you have to give that in the parent definition...

+--- root
      +--- pom.xml (Parent)
      +--- module1
             +-- pom.xml (child 1)

You should also define a relativePath in your childs as well...

<parent>
    <groupId>com.example</groupId>
    <artifactId>parent</artifactId>
    <version>1.2-SNAPSHOT</version>
    <relativePath>../pom.xml</version>
</parent>
<groupId>...</groupId>
<artifactId>...</artifactId>

If you done so you should never change the version number by hand in your parent...let the release plugin do the work it will change the version entries in all childs (parents) appropietaley...if you really need to change things sometimes use the maven-version-plugin...

khmarbaise
I'm pretty sure that the relativePath defaults to `../pom.xml` so adding this won't make any difference
Don
But it makes things clearer to understand.
khmarbaise
I don't have a version defined in the child module, I just have a reference to the version of the parent module that the child depends on. The latter is what I'm trying to eliminate, because it will always be whatever the current version of the parent module is.
Don
"But it makes things clearer to understand"True, but at the cost of extra configuration. In this case I'm willing to trade a little less clarity for a little less config, YMMV.
Don
Ah...seemed to be a misunderstanding...The version in parent area is necessary. There is no possibility to remove that. If you need to change use the release plugin or the version plugin.
khmarbaise
A: 

You can set the version only in parent pom.xml, it's inherited. In inter-module dependencies you can use <version>${project.version}</version> .

binary_runner
In the child modules you can omit the version entry this will result in having the same version number as in the parent module. On the other hand any placeholders will be replaced during a release.
khmarbaise
+1  A: 

I tried replacing the above with (...) and (...) but neither of these work. I'm using Maven version 2.1.0.

Not possible. With Maven 2.x, you must declare the parent element in child module and the parent element must include a hard-coded version (you can't omit it and you can't use a property, see this previous answer and MNG-624).

However, Maven 3.1 will supports versionless parent elements (see this previous answer).

Meanwhile, some plugin can make the maintenance a bit easier like the Maven Release Plugin or the Versions Maven Plugin and its versions:set or versions:update-child-modules goals.

Pascal Thivent
Thanks Pascal, I guess I'll just have to wait until my company upgrades to Maven 3.1, though it's likely the sun will burn out before that happens.
Don
@Don You're welcome. `versions:set` is a decent workaround until the sun EOL :)
Pascal Thivent