SoFunction
Updated on 2025-03-04

How to remove unwanted modules for maven project packaging

Scene

  • my-project engineering dependencies my-core and my-common
  • my-project in total project AAA
  • Then the total project pom also contains other projects
  • Before, every install was a pom that executed the total project, so that other projects were packaged, wasting time and resources.
  • I hope to only package my-project and the projects it depends on

Two solutions

1. Use pom to distinguish

Rewrite the pom file, and then add the project that needs to be recompiled into modules

......
......

<modules>
    <module>my-core</module>
    <module>my-common</module>
    <module>my-project</module>
</modules>

......
......

Then, when compiling, you can specify the pom file (if not specified, the default execution is performed)

mvn install -=true  -f 

2. Specify module translation

Directly specify the project that needs to be precompiled in the compile command

mvn install -=true -pl my-common,my-core,my-project

illustrate:

  • The above command is skipped when install test (-=true)
  • Then specify that only package my-common,my-core,my-project

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.