Reputation: 1127
I have multi module project which is very simple.
Directory structure:
C:\acme-project\parent
C:\acme-project\alpha
C:\acme-project\beta
Logical structure:
parent
/ \
alpha <- beta
I cannot build the beta
because it depends on the alpha
. And Meven doesn't want to build the alpha during the beta's build process!
C:\acme-project\beta> mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building beta 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.company:alpha:jar:1.0-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.263 s
[INFO] Finished at: 2017-03-28T15:00:34+03:00
[INFO] Final Memory: 16M/220M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project beta: Could not resolve dependencies for project com.company:beta:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: com.company:alpha:jar:1.0-SNAPSHOT: Could not find artifact com.company:alpha:jar:1.0-SNAPSHOT -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
My POMs :
C:\acme-project\parent\parent.pom :
<?xml version='1.0' encoding='UTF-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>parent</artifactId>
<version>1</version>
<packaging>pom</packaging>
<modules>
<module>../alpha</module>
<module>../beta</module>
</modules>
</project>
C:\acme-project\alpha\alpha.com :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>parent</artifactId>
<groupId>com.company</groupId>
<version>1</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>alpha</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
C:\acme-project\beta\beta.pom :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.company</groupId>
<artifactId>parent</artifactId>
<version>1</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<artifactId>beta</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.company</groupId>
<artifactId>alpha</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
I can build the acme-project running mvn package
in C:...\parent. But in case of more complex project parent
could have 100 sub-modules. And obviously I don't want to build 98 modules (others that beta
doesn't depend on) just to make Maven happy.
Upvotes: 1
Views: 1026
Reputation: 1638
If you want to build just the projects that beta
depends on, go to the root aggregator (i.e., the project with all the <modules>
; parent
in your case) and then ask Maven to build only beta
and its dependencies in the current reactor:
cd parent
mvn package --projects com.company:beta --also-make
FYI, this can be abbreviated:
mvn package -pl :beta -am
In your minimal example, the above command will still build everything (as beta
depends on alpha
and implicitly on the parent
), but in larger reactors it will build just the minimal subset necessary to build beta
.
Upvotes: 4