Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inter Project Dependencies in Maven

Tags:

maven-2

I have two maven projects: project-api project-impl

project-impl's POM specifies a dependency on project-api. The top level aggregation pom lists modules project-api and project-impl.

If I run compile at top level, the dependencies resolves correctly. If I run compile at project-impl, then it can't find dependency project-api. How can I set up maven such that when project-impl compiles, it first compiles and collects its dependencies on other projects?

like image 804
Candy Chiu Avatar asked Jun 03 '10 22:06

Candy Chiu


2 Answers

you can only do that from the root project

mvn -pl child -am 

this will build your sub project and also all dependencies in the same tree. in general, when you have a multi module project, you should always build from the parent, never from the child. And if you only want to build one or two child projects, do this:

mvn -pl child

OR

mvn -pl child2,child3

(projects child2 and child3 are build, but child1 and child4 aren't)

like image 125
Sean Patrick Floyd Avatar answered Oct 21 '22 15:10

Sean Patrick Floyd


You need a dependency on api in the POM of the impl module.

When you compile on the toplevel project the reactor will figure out the right order to build things.

To separately build the project-impl you must first 'mvn install' the the project-api module or it will not find the right dependencies.

If you work in a team, an automated build server which pushes artifacts to a central repository can help to ease the pain here because this can drive you nuts.

This all works very well, however ot works the "maven" way, which is not always as we humans would do things.

like image 33
Peter Tillemans Avatar answered Oct 21 '22 14:10

Peter Tillemans