What is the method for packaging dependencies for a Maven subproject?

The method for packaging dependent sub-projects in Maven is to use Maven’s multi-module project structure. In a multi-module project, a parent project can contain multiple sub-projects that can depend on each other.

Here is a method to implement Maven project dependency packaging for subprojects:

  1. components
<modules>
  <module>子项目1路径</module>
  <module>子项目2路径</module>
  ...
</modules>
  1. mom or dad
<parent>
  <groupId>父项目Group ID</groupId>
  <artifactId>父项目Artifact ID</artifactId>
  <version>父项目版本号</version>
</parent>
<dependencies>
  <dependency>
    <groupId>依赖的子项目Group ID</groupId>
    <artifactId>依赖的子项目Artifact ID</artifactId>
    <version>依赖的子项目版本号</version>
  </dependency>
</dependencies>
  1. Packaging: Under the root directory of the parent project, running the `mvn package` command will package all child projects. The packaged JAR files of the child projects will be placed in their respective target directories after packaging.
  2. Subproject dependencies: In other projects, you can use the packaged subprojects by adding the corresponding subproject dependencies in the pom.xml file. For example:
<dependencies>
  <dependency>
    <groupId>子项目Group ID</groupId>
    <artifactId>子项目Artifact ID</artifactId>
    <version>子项目版本号</version>
  </dependency>
</dependencies>

By following the above steps, you can achieve the packaging of dependencies between Maven subprojects.

广告
Closing in 10 seconds
bannerAds