user17544628
user17544628

Reputation:

Remove SNAPSHOT from all Maven sub-modules, but honor version

Use Case

I am working on a multi-module project and I am trying to drop -SNAPSHOT for all child modules that have different versions.

Example

For the purposes of this exercise we can assume there are two sub-modules. The articles Maven Simple Project Archetype and Create an archetype from a multi-module project can be referenced to follow along.

Parent - 1.0.0-SNAPSHOT
ChildA - 1.2.3-SNAPSHOT
ChildB - 1.0.0-SNAPSHOT

Results

When I run mvn versions:set -D removeSnapshot -D processAllModules I expect the versions to change as indicated below.

Parent - 1.0.0
ChildA - 1.2.3
ChildB - 1.0.0

But, it seems -SNAPSHOT is stripped from all versions except the children that have a different version from the parent.

Parent - 1.0.0
ChildA - 1.2.3-SNAPSHOT
ChildB - 1.0.0

Is there any way to run the mvn versions:set command to honor the version number, while stripping the -SNAPSHOT postfix?


UPDATE #1

Running mvn versions:set -D removeSnapshot=true yields the same results as running mvn versions:set -D removeSnapshot -D processAllModules.

Parent - 1.0.0
ChildA - 1.2.3-SNAPSHOT
ChildB - 1.0.0

Upvotes: 1

Views: 517

Answers (1)

user17544628
user17544628

Reputation:

As per the Maven Enforcer documentation for multi-module projects...

The best practice in Maven is that all childs inherit the version from their parent and don't define a new version which looks like this:

<parent>
  <groupId>...</groupId>
  <artifactId>...</artifactId>
  <version>1.0-SNAPSHOT</version>
</parent>

<artifactId>module1</artifactId>
(..)

Additional use cases can be found in the linked article above.

Upvotes: 1

Related Questions