我使用 Maven 程序集插件为我的多模块项目创建程序集。从这个多模块项目构建了两个独立的应用程序,每个应用程序都有一组单独的依赖项。我制作了一个自定义程序集描述符,它将两个目录(针对每个应用程序)与模块构建及其各自的依赖项组合在一起。它做的一切都很好,但有一件事 - 它将两个模块的依赖关系放到彼此的程序集中。
以下是我的项目的简化版本,具有完全相同的行为。
考虑一个由两个模块和一个组装模块组成的项目:
APP
module1
module2
assembly
我添加了依赖项纯粹是为了演示:
com.test.app:module1:jar:1.0
\- commons-cli:commons-cli:jar:1.2:compile
com.test.app:module2:jar:1.0
\- commons-daemon:commons-daemon:jar:1.0.8:compile
这是父 POM:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>app</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>module1</module>
<module>module2</module>
<module>assembly</module>
</modules>
</project>
模块1 POM:
<project>
<parent>
<groupId>com.test</groupId>
<artifactId>app</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.app</groupId>
<artifactId>module1</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>
模块2 POM:
<project>
<parent>
<groupId>com.test</groupId>
<artifactId>app</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.app</groupId>
<artifactId>module2</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>commons-daemon</groupId>
<artifactId>commons-daemon</artifactId>
<version>1.0.8</version>
</dependency>
</dependencies>
</project>
组装POM:
<project>
<parent>
<groupId>com.test</groupId>
<artifactId>app</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.app</groupId>
<artifactId>assembly</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.2</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/descriptor.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
</project>
最后,程序集描述符:
<assembly>
<id>distribution</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>dir</format>
</formats>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.test.app:module1:jar</include>
</includes>
<binaries>
<outputDirectory>module1</outputDirectory>
<unpack>false</unpack>
<dependencySets>
<dependencySet>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
</binaries>
</moduleSet>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.test.app:module2:jar</include>
</includes>
<binaries>
<outputDirectory>module2</outputDirectory>
<unpack>false</unpack>
<dependencySets>
<dependencySet>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
</binaries>
</moduleSet>
</moduleSets>
</assembly>
如您所见,程序集绑定到包阶段。所以,当我执行
mvn package
从父目录,我有以下程序集
module1/
commons-cli-1.2.jar
commons-daemon-1.0.8.jar
module1-1.0.jar
module2/
commons-cli-1.2.jar
commons-daemon-1.0.8.jar
module2-1.0.jar
基本上这里的问题是module1不依赖commons-daemon,但是汇编插件已经包含了依赖。同样,对于 module2 和 commons-cli。
有人可以解释为什么程序集插件会这样吗?
什么是解决方案?