Reputation: 969
I have a maven project that I'd like to share with several of my other projects. It has some custom code, and then a few dependencies on things like log4j, jasypt, etc.
I build it and install it to my local maven repo. I can see it's successfully put there. Looking at .m2/repository/derp/Foo/1.0 it has a .pom with all its dependencies defined.
I can also define it as a dependency in my higher level projects, and it compiles.
<dependency>
<groupId>my.group</groupId>
<artifactId>Foo</artifactId>
<version>1.0</version>
</dependency>
I can see the Jar in my 'Maven Dependencies' in eclipse, and expanding that jar I can see it has the correct pom with dependencies in META-INF/maven/derp/Foo/pom.xml.
But my top level project above Foo isn't getting the dependencies that Foo needs. I get runtime exceptions, and I can see none of the transitive dependency jars are in my maven dependencies in eclipse.
What do I need to do to make sure Maven knows to look at the Pom for Foo in my local repo, so it will get all the transitive dependencies it needs?
----- edit -----
Answer to comment below, they are defined like this, with the dependencies tag at the top level under the project tag.
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.2</version>
</dependency>
etc...
These are the jars that maven correctly finds when I am just building and running this Foo project, but maven doesn't include these jars if a project depends on Foo, (Bar), and I find out when I try to run Bar.
Upvotes: 3
Views: 1706
Reputation: 1052
What does "top level project above Foo isn't getting the dependencies" mean?
Anything "above" Foo
in the build reactor should depend directly on Foo
as you have stated. The <dependency/>
specified will resolve to Foo
's dependencies (within the scope that Foo
specifies).
Without understanding the specifics of your project, it's improbable that we can to help you any further.
Some possible common situations:
test
scoped dependencies in some non-test
phase of execution. Just not true.java
runtime to load those dependencies for you automagically. That's also not true. exec:java
goal on the maven exec plugin and specify your desired resolution scope within the <configuration/>
, possibly also for that <execution/>
.<dependencyManagement>
for <dependencies>
. This happens way more than I would have expected.Upvotes: 1