Forin
Forin

Reputation: 1619

Using dependencies of an artifact

I have a complex Spring project with tens of dependencies and modules. I notice that some of them might be replaced by spring-boot-starters.

However, when I'm replacing some dependencies with starters in main, parent pom, I'm getting errors in children modules.

Here's an example:

PARENT POM

<dependencyManagement>
  <dependencies>      
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-activemq</artifactId>
      <version>2.0.5.RELEASE</version>
    </dependency>
  </dependencies>
</dependencyManagement>

MODULE POM

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jms</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter</artifactId>
</dependency>

According to maven repository spring-boot-starter-activemq depends on, among others, spring-boot-starter and spring-jms.

Should these dependencies be available for modules?

Is there a way to use dependencies like that? I would make pom files shorter.

Or maybe is it a bad idea to do it like that and I should define all dependencies I will use in dependencyManagement?

Upvotes: 0

Views: 30

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35893

In a POM, you should have all the dependencies that you directly use in your code. Do not rely on transitive resolution for things you actively use.

Your construction does not work because you did not manage the spring-jsm and spring-boot-starter in your dependencyManagement. Being a dependency of the managed dependency does not help.

Upvotes: 1

Related Questions