0

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?

Xiang Wei Huang
  • 336
  • 1
  • 9

1 Answers1

2

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!

cyberbrain
  • 3,433
  • 1
  • 12
  • 22
  • Project 1's pom has declared dependency on Project 2. Project 2 is in my m.2 folder, I meant to say that it's imported there through IntelliJ's import function, sorry. As for the scope, Project 2's declare of `spring-boot-starter-web-services` has no scope, so I think it defaults to `compile` scope? – Xiang Wei Huang Sep 12 '22 at 08:49
  • Turns out although the jar is installed, Maven auto generated an empty `pom` so there's no transitive dependencies to be found. [Refer to this](https://stackoverflow.com/questions/36559692/maven-install-transitive-dependencies) for detailed explanations. Thanks for helping! The conditions that might cause Maven to work with old poms in your post are listed very easy to understand! Your post also hinted me about the phrase 'Transitive Dependencies.' Might refer to this post as cheat sheet later on. – Xiang Wei Huang Sep 12 '22 at 09:32
  • 1
    Empty pom in local repo is really a nasty thing. Good that you found it! :) And yes, the default scope of maven is `compile`. – cyberbrain Sep 12 '22 at 18:39