Question

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?

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top