5

In one module, I use spring-boot-starter-activemq:2.07.RELEASE which depends on activemq-broker:5.15.8 which depends on guava:18.0.

In another module, I would like to use guava, so I have to use:

<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
  <version>18.0</version>
</dependency>

If I use an higher version in my pom.xml this version will be also used by activemq-broker due to the nearest definition rule of the dependency mediation (see Introduction to the Dependency Mechanism)

I don't want to provide a different version of Guava than what is asked by activemq-broker. So in order to synchronize the versions, each time there is a Spring Boot upgrade, I need to check manually the versions in order to synchronize them.

I use activemq-broker and guava as an example but my question is more general: How to automatically reuse a dependency version from one module into another?

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240
  • Did you try setting your guava dependency as provided in your pom.xml? In case you use spring-boot-starter-activemq as compile (or runtime) and both the active-mq-broker and guava are compile/runtime dependencies of their parents you should be able to re-use them by defining the dependency as provided – Abaddon666 Dec 19 '18 at 09:04
  • I'm interested in the answer also. I do it manually every time – Marouane Lakhal Dec 19 '18 at 09:41
  • I understand spring-boot-starter-activemq dependency is defined for one module, and you want to add guava dependency to the parent pom, right? Because if you are working in simple module project, you just don't need to declare guava dependency, as dependencies are transitive. – jaudo Dec 19 '18 at 10:14
  • @jaudo, yes, it's a multi-modules project, I've updated my answer. – Ortomala Lokni Dec 19 '18 at 10:32
  • @Abaddon666 `provided` is defined as `indicates you expect the JDK or a container to provide the dependency at runtime.` I need these libraries at compile time. – Ortomala Lokni Dec 19 '18 at 10:43

2 Answers2

2

I would define a parent for my project where dependency management will be handled.(You probably already have this). In the parents dependendency management section, I would import dependency management of activemq-parent. This way you can just define dependencies, without explicit versions in the childs.

Also you can make your parent inherit from spring-boot-dependencies to get versions properties. (In this example activemq.version is fetched from this)

Example: Parent pom

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.1.1.RELEASE</version>
</parent>

<dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-parent</artifactId>
        <version>${activemq.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      .....
</dependencyManagement>

If Your parent doesn't inherit from spring-boot-dependencies, You would have to write specific version instead of ${activemq.version} for activemq-parent

After this in the child

<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
</dependency>

Version of the guava will be same as activemq-parent. ( Because it is defined there)

miskender
  • 7,460
  • 1
  • 19
  • 23
-1

In module where you are definign dependency

activemq-broker:5.15.8

also defibe and add which ever version of guava you like to use while other can inherit other versions of guava may be from grandparent pom.

Zafar Ali
  • 37
  • 1
  • 8