"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How can I build a specific module in a Maven multi-module project without encountering dependency errors?

How can I build a specific module in a Maven multi-module project without encountering dependency errors?

Published on 2024-11-12
Browse:258

How can I build a specific module in a Maven multi-module project without encountering dependency errors?

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:

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

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
Latest tutorial More>

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