tags:

views:

157

answers:

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?

A: 

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.

Peter Tillemans
+1  A: 

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)

seanizer
+1 The reactor advanced options are the way to go
Pascal Thivent
mvn -pl -am works.
Candy Chiu