Building a Specific Module in a Maven Multi-Module Project
In a Maven multi-module project, compiling all sub-modules can be achieved using mvn compile in the parent project. However, challenges arise when running specific commands for individual sub-modules.
For example, packaging a war for project B in a project with sub-modules A, B, and C (where both B and C depend on A) results in errors due to missing dependencies.
To address this, Maven provides advanced reactor options:
Best Practice
To package project B along with its required modules, use the following command in the parent project directory:
mvn install -pl B -am
This command will build project B and all modules on which it depends. Note that if the project's artifactId differs from the directory name, the colon syntax should be used, as in:
mvn install -pl :B -am
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3