Maven 어셈블리 플러그인을 사용하여 다중 모듈 프로젝트의 어셈블리를 만듭니다. 이 다중 모듈 프로젝트에는 각각 별도의 종속성 세트가있는 두 개의 개별 응용 프로그램이 있습니다. 모듈 빌드와 각각의 종속성을 가진 두 개의 디렉토리 (각 애플리케이션 용)를 어셈블하는 커스텀 어셈블리 디스크립터를 만들었다. 모든 것을 훌륭하게 수행하지만 한 가지만 - 두 모듈의 종속성을 서로의 어셈블리에 적용합니다.Maven 어셈블리 플러그인을 사용하여 다중 모듈 종속성 관리
다음은 정확하게 동일한 동작을하는 내 프로젝트의 단순화 된 버전입니다. 데모 순수
APP
module1
module2
assembly
내가 추가 한 종속 관계 :
은 두 개의 모듈로 구성된 프로젝트와 어셈블리 모듈을 고려<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>
: 여기
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의 module1 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
기본적으로 다음과 같은 어셈블리를 가지고, 여기에 문제는 모듈 1은 공유지 - 데몬에 의존하지 않는, 그러나 조립 플러그인이 포함되어있다 의존. 마찬가지로 module2와 commons-cli도 있습니다.
왜 어셈블리 플러그인이 이런 식으로 행동하는지 설명 할 수 있습니까?
해결책은 무엇입니까?
'maven-assembly-plugin'의 이상한 동작을 기대하지 않습니다 ... 부모로부터 어셈블리 프로젝트로 푸시 된 의존성이 없습니까? 어셈블리 프로젝트를 위해 생성 된 종속성 트리를 보여줍니다. –
어셈블리 모듈의 종속성 트리는 POM에 종속성 선언이 없으므로 분명 비어 있습니다. – sertsy