javamavenpom.xmldependency-managementcicd

Maven version management w multiple child modules


I'm putting together a maven project which I've broken down into four sub modules and am noticing that I need for each child module to reference it's parent module by a specific version number. What I am not liking is if we need to update the version I need to update it in the parent and each of the child module's reference to the parents. So I tried adding a variable to the parent pom.xml and used them to populate the references to the parent module which would let me update the whole package in a single place but am noticing this warning message now.

[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.xyz:abc-common:jar:1.7.1-SNAPSHOT
[WARNING] 'version' contains an expression but should be a constant. @ xyz:abc:${app.version}, C:\Tools\BSF2\abc\pom.xml, line 25, column 14
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.xyz:abc:pom:1.7.1-SNAPSHOT
[WARNING] 'version' contains an expression but should be a constant. @ xyz:abc:${app.version}, C:\Tools\BSF2\abc\pom.xml, line 25, column 14
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]

So is managing maven versioning going to always be me updating n+1 files where n is the number of child modules or is there a simpler way to do this where I only need to update version info in a single file location> I'd like to avoid human error when doing releases.

There have been suggestions that we should be able to omit specifying the version to the parent module but when I do that I get this error

[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] 'parent.version' is missing. @ line 7, column 13
[FATAL] Non-resolvable parent POM for com.xyz:abc-zip:${abc.version}: The following artifacts could not be resolved: com.xyz:abc:pom:${abc.version} (absent): Could not transfer artifact com.xyz:abc:pom:${abc.version} from/to maven-public (https://nexus.xyz.tools/repository/maven-public): status code: 400, reason phrase: Invalid repository path (400) and 'parent.relativePath' points at wrong local POM @ line 7, column 13
 @
[ERROR] The build could not read 4 projects -> [Help 1]
[ERROR]
[ERROR]   The project xyz:abc-common:[unknown-version] (C:\Tools\BSF2\abc\abc-common\pom.xml) has 1 error
[ERROR]     'parent.version' is missing. @ line 7, column 13

Here is me omitting the version specification to the parent module in the child pom.xml.

<parent>
    <groupId>xyz</groupId> 
    <artifactId>abc</artifactId>
    <!--<version>${abc.version}</version>-->
</parent>

Note that my question is different from this: Maven property not resolved in parent tag as I'm not using spring boot libraries and I am asking what the best practice is and if it is expected that multi module projects require multiple files to be updated (not counting the dependency references). If so this is a glaring issue with the maven system as can be very open to human error.


Solution

  • You need a constant as parent version in Maven 3, for Maven 4 you will can skip parent definition from children.

    For easy manage it you can use:

    mvn versions:set
    

    will update every modules.