1

I have a fairly typical plugin architecture that looks something like this (just larger):

project
    core
    data
    main
    ui

The parent project has a version number defined, is packaged as a pom and defines modules in it's pom.xml:

<groupId>group</groupId>
<artifactId>project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

...

<modules>
    <module>core</module>
    <module>data</module>
    <module>main</module>
    <module>ui</module>
</modules>

All of the sub-modules have many references to the parent's version number everywhere. Here is the an example of what the main module looks like to give you an idea:

<parent>
    <groupId>group</groupId>
    <artifactId>project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<groupId>group</groupId>
<artifactId>project.main</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
    <java.version>11</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>group</groupId>
        <artifactId>group.core</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>group</groupId>
        <artifactId>group.data</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>group</groupId>
        <artifactId>group.ui</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

We're getting tired of having to change the version number over, and over, and over with each release in every parent block, in every artifact block, and in every dependency block for each and every module. On a few occasions, someone used search/replace which hit other files and messed up the build. We tried using properties, but that doesn't work inside the parent definitions for some nonsensical reason.

The version number defined in the parent is the only place we care to manage. We don't even need the sub-modules to even HAVE versions (or artifacts, for that matter). We can do this in our other Ant projects. We can do this in our other Gradle projects. I can't imagine this being impossible in Maven, so I am guessing we are missing something.

How can we define the project's version number in one place, and have that used in all of the parent, artifact, and dependency sections in our modules?

Cypher
  • 2,608
  • 5
  • 27
  • 41
  • 1
    No your not missing anything I think. If you dont care about the version of the submodules just define it in the parent and the relation to the parent in the sub-modules. use ${project.version} in the dependencyManagement in the parent to define the prefered version of the modules and from here all dependencies dont need a version anymore. – wemu Jul 19 '19 at 20:37

1 Answers1

0

Version maven plugin offers the possibility of changing the subprojects version in one shot. After including the plugin:

mvn versions:set -DnewVersion=<your version>

And if everything is correct:

mvn versions:commit
pedrohreis
  • 1,030
  • 2
  • 14
  • 33
  • I'm assuming because you're recommending using a plugin, that setting a variable and using it throughout the build scripts is not an option? – Cypher Jul 19 '19 at 23:18