Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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 :

Run the command from parent/.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top