HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaCritical

Maven Modules + Building a Single Specific Module

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
mavenmodulespecificsinglebuildingmodules

Problem

I have a multi-module Maven project with a parent project P and three sub-modules A, B, and C. Both B and C are war projects and both depend on A.

I can type mvn compile in P and have all of the sub-modules properly compiled. The problem comes when I want to do operations for specific modules.

I'd like to be able to package a war for project B, but when I run the package command from B's directory, it complains that it can't find the dependencies for A.

I understand from this question: Maven and dependent modules that perhaps Maven isn't really designed for this type of dependency resolution, but that begs the question of how do I package B?

-
Do I have to run mvn package for the entire project hierarchy when I really just want B?

-
Do I have to install snapshots of A into my local repository every time I want to package B?

This second scenario isn't much fun when A is still under active development.

Any best practices here?

Solution

Any best practices here?

Use the Maven advanced reactor options, more specifically:

-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


So just cd into the parent P directory and run:

mvn install -pl B -am


And this will build B and the modules required by B.

Note that you need to use a colon if you are referencing an artifactId which differs from the directory name:

mvn install -pl :B -am


As described here:

  • Define modules list which shall be build in Maven multiproject build

Code Snippets

-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
mvn install -pl B -am
mvn install -pl :B -am

Context

Stack Overflow Q#1114026, score: 1009

Revisions (0)

No revisions yet.