Question

I have a multimodule maven project, where module share dependencies. By share I mean use the same dependencies. However each module declares dependencies itself. To keep sanity (yeah, maven, sanity, I know), and to have all modules using the same version of dependencies, parent pom declares properties with version numbers:

<properties>
   <dependency1.version>1.0-SNAPSHOT</dependency1.version>
   <dependency2.version>1.1-SNAPSHOT</dependency2.version>
</properties>

and all modules use that like:

<dependency>
  <groupId>group</groupId>
  <artifactId>dependency1</artifactId>
  <version>${dependency1.version}</version>
</dependency>

I'm quite happy with this setup, as it allows me to change dependencies versions in 1 place.

Now I have a bunch of dependencies that I maintain myself. Release of those is automatic and very simple, basically:

mvn release:prepare release:perform -B

now I want to automate further and in the main project I run:

mvn versions:update-properties

(basically I also run: "mvn versions:use-releases" to change usual dependencies if needed, but it's out of the scope of this question).

After this update-properties run, properties in my main projects pom point to releases (which is good). However if my modules use properties to define versions of other dependencies and those projects have newer versions available, those properties are also changed.

Is there any way to limit damage from update-properties? versions:use-release takes includes property, so I can use it only on mine artefacts. Cannot find anything similar for update-properties.

I can revert all poms besides parent one and commit/push only that, but it doesn't seem elegant.

Was it helpful?

Solution

It sounds that you didn't understand the concept of maven. In such circumstances you should use dependencyManagement in the parent pom like the following:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.inject</groupId>
      <artifactId>guice</artifactId>
      <version>3.0</version>
    </dependency>
    ...
   </dependencies>
</dependencyManagement>

In you modules you just use a dependency like this:

  <dependencies>
    <dependency>
      <groupId>com.google.inject</groupId>
      <artifactId>guice</artifactId>
    </dependency>
    ...
   </dependencies>

The important step is not to define the version. In this case the version will be used which is defined by the dependency management block. So you don't need to define properties etc. and furthermore you have a single point where you can define and change the dependencies in particular the versions.

Apart from that it's possible to limit the properties which will be changed defining it on the command line on the version:update-properties call.

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