views:

25

answers:

1

I have the following source layout:

.
├── pom.xml
├── modules (has pom)
│   ├── module1 (has pom) 
│   └── module2 (has pom)
│   └── moduleN (has pom)
└── webapp1 (has pom)
└── webapp2 (has pom)

webapp1 and webapp2 depends on all of the modules (the modules being DAO, services, etc). At the moment, I build everything from the root and mvn package gives me two WAR files.

How do I build only webapp1 or webapp2?

If I cd into webapp1 and run mvn package it says it can't download moduleX.jar (this is with a clean repository). Surely Maven should be able to deduce that those modules need to be built first as dependencies?

+1  A: 

How do I build only webapp1 or webapp2?

Use "advanced reactor options". From the root:

mvn install -pl webapp1 -am

This tells maven to install webapp1 and the projects on which webapp1 depends (in the right order).

The help (mvn -h) documents these commands like this:

-pl, --projects
        Build specified reactor projects instead of all projects
-am, --also-make
        If project list is specified, also build projects required by the list

Note that you need to invoke install, dependencies are always resolved through the local repository (so you need to install them). I was wrong, calling package does work (I don't know how/why, but it does).

Pascal Thivent
Thanks! I often overlook the command-line options.
opyate
Pascal, if I clear my packages from my local (rm -rf ~/.m2/repository/com/mycompany) and then run mvn -pl webapp1 -am package, then the repo stays the same, i.e. my JAR files aren't copied to local. This is actually a nice side-effect, but does this counter what you said about having to "install"?
opyate
*I clear my packages from my local (...) and then run mvn -pl webapp1 -am package, then the repo stays the same* Yes, `package` doesn't `install` to the local repository (but why are you "messing" with the local repository?). *This is actually a nice side-effect, but does this counter what you said about having to "install"?* Wow, I just double checked on a pet project and you're right, calling `package` only works. I wasn't aware of this (and I don't understand why/how it works).
Pascal Thivent
I was "messing" with the local just to check what side-effects each phase has. Thanks for your help, Pascal :)
opyate