[SOLVED] Does Maven resolve dependencies of dependencies?


This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under
CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

Issue

The current project I’m participating in has such structure:

  • Project 1
    • depends on Project2 in pom
    • checks if object is instanceof SomeClass (mentioned below)
  • Project 2
    • depends on spring-boot-starter-web-services in pom
    • is imported into Project1 as a .jar file through IntelliJ IDEA project settings
    • has a class, SomeClass that extends org.springframework.ws.client.core.support.WebServiceGatewaySupport

When running mvn clean package, the error below shows up:

cannot access  org.springframework.ws.client.core.support.WebServiceGatewaySupport

and the error’s line refers to where instanceof SomeClass is written.

Checking the External Libraries in IntelliJ IDEA, seems like libraries related to spring-boot-starter-web-services simply just didn’t show up. Adding spring-boot-starter-web-services in project1’s pom fixes this but it seems confusing because project2, which project1 depends on, already has that in its pom.

Is this intended behaviour of Maven? Does Maven install dependencies of dependencies? Or is there something I still need to configure to make this work?

Solution

It depends: usually maven cares for transitive dependencies.

But if your Project2 is

  1. neither available in a remote Repo (because you didn’t mvn deploy it)
  2. nor in the local Repo (because you didn’t mvn install)
  3. nor you have it as sibling module in a modularized project

or you didn’t update (in the cases of 1 and 2) it for a long time there, maven could try to work with an old version of the poms that might not yet contain that dependencies.

Another source of problems could be if Project 2 declares its dependencies in the maven scope of provided.

And you wrote that Project 1 depends on Project 2 “through IntelliJ IDEA project settings”. This is not sufficient for maven to resolve dependencies, you have to declare the dependency in the maven pom.xml!

Answered By – cyberbrain

people found this article helpful. What about you?