4

I have parent pom with modules defined like so :

parent pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    <modelVersion>4.0.0</modelVersion>
    <groupId>parent</groupId>
    <artifactId>parent</artifactId>
    <version>1.0.2-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>../proj1</module>
        <module>../proj2</module>
    </modules>

</project>

Here are the child module pom files :

proj2 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0     http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>parent</groupId>
        <artifactId>parent</artifactId>
        <version>1.0.2-SNAPSHOT</version>
        <relativePath>../parent/pom.xml</relativePath>
    </parent>

    <groupId>proj2</groupId>
    <artifactId>proj2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
</project>

proj1 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmln:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
     http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>parent</groupId>
        <artifactId>parent</artifactId>
        <version>1.0.2-SNAPSHOT</version>
        <relativePath>../parent/pom.xml</relativePath>
    </parent>

    <groupId>proj1</groupId>
    <artifactId>proj1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
</project>

But when I use the versions plugin it just sets the parent version number and not its modules. Here is the command I am using :

versions:set -DnewVersion=1.0.2-SNAPSHOT

Here is the output :

[INFO] proj1 ...................................... SKIPPED
[INFO] proj2 ...................................... SKIPPED
[INFO] parent ......................................SUCCESS

The sub modules are being skipped. How can I enable the sub modules to be also updated and not just the parent?

Update : ive tried deleting the version tag from the child module so child module now is :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>parent</groupId>
        <artifactId>parent</artifactId>
        <version>1.0.2-SNAPSHOT</version>
        <relativePath>../parent/pom.xml</relativePath>
    </parent>

  <groupId>proj2</groupId>
  <artifactId>proj2</artifactId>
  <packaging>war</packaging>
</project>    


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
        <groupId>parent</groupId>
        <artifactId>parent</artifactId>
        <version>1.0.2-SNAPSHOT</version>
        <relativePath>../parent/pom.xml</relativePath>
    </parent>

  <groupId>proj1</groupId>
  <artifactId>proj1</artifactId>
    <packaging>war</packaging>
</project>   

But version number is not being updated in child pom files.

Update : Here is how I think this process works, please feel free to suggest revisions :

Theoritically (I havent tested this) in a nested file structure Maven will update the individual version numbers for each child module when the goal : 'ons:set -DnewVersion=1.0.2-SNAPSHOT' is run.

However in a flat file structure it is not required to specify the version number in the child modules if the parent module has the same version. This is because the child version number if not set will use the parent version number. So to update all of the child modules of a parent module just update the version numer of the parent module, if all of the child modules do not have version number set then they will have same version number as parent module.

Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65
user701254
  • 3,935
  • 7
  • 42
  • 53
  • Are you specifying the version on the child modules pom file? – Augusto Sep 18 '12 at 10:44
  • Are you able to move your submodules projects into you parent dir ? The flat structure is really not recommended. You may have issue, like in maven-realease-plugin. But I'm not sure this is the real problem. – Jean-Rémy Revy Sep 18 '12 at 10:47
  • @Augusto yes, im specifiying the version on the child modules, ive updated the question to include these pom files – user701254 Sep 18 '12 at 10:56
  • @Jean-Rémy Revy by move do you mean copy the entire pom files for the submodules into the parent pom ? Why do you mean by flat structure, what is the alternative ? – user701254 Sep 18 '12 at 10:57
  • I find it strange that your submodules don't define the parent as the actual parent module. Usually submodules inherit the version from the parent module (at least that's the usual way of doing things with maven) – Augusto Sep 18 '12 at 11:02
  • @Augusto ive updated the pom files to include a reference to the parent but same result when try to update the verson number. – user701254 Sep 18 '12 at 11:19
  • You cannot remove the parent version in the child pom but you can remove the version of the child. – maba Sep 18 '12 at 12:45
  • @maba thanks, ive updated to remove the version from the child but the version number is still not being updated when I run the plugin. – user701254 Sep 18 '12 at 12:50
  • Look at the answer from Jean-Rémy Revy. You should use that structure for your code. – maba Sep 18 '12 at 13:00
  • By the way. Now it must be working. If you run the `version:set` with a new version `1.0.3-SNAPSHOT` you will see that the parent pom and the child poms will have a new version. Try to build with `mvn install` and look at the war files to see their new versions. – maba Sep 18 '12 at 13:04
  • @maba please see question edit – user701254 Sep 18 '12 at 13:45

3 Answers3

2

This probably won't help you, but is sounds like this bug : JIRA MRELEASE-261 : release:prepare should support flat directory multi-module projects

The flat structure is not recommended. This is an "old pratice" of (Eclipse ?) developers. I used it for a long time, and then discover the benefits of Maven approach.

Old way :

parent
`-- pom.xml
submodule 1
`-- pom.xml
submodule 2
`-- pom.xml

Maven way :

parent
|-- submodule 1
|   `-- pom.xml
|-- submodule 2
|   `-- pom.xml
`-- pom.xml

You may find more information here :

Community
  • 1
  • 1
Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65
  • the projects are setup in a flat file structure as it makes it easier for managing each project individually. A nested file structure does not make sense to me since then the code for each war file will have to be under the same parent project. – user701254 Sep 18 '12 at 13:39
1

Ok, now if your child modules are referencing the parent pom, you can delete the version tag from the child module poms, so they the version will get inherited from the parent pom.

Since the version gets inherited from the pom, when you use the version plugin, all the the modules will have the same version.

Augusto
  • 28,839
  • 5
  • 58
  • 88
0

Run the command from parent/.

yihtserns
  • 1,143
  • 10
  • 17