私の問題の概要: マルチモジュール プロジェクトでは、モジュールの 1 つが別のモジュールに依存しています。を使用してこのモジュールの uber jar をビルドするとmaven-shade-plugin
、すべての依存関係が正しく含まれますが、他のモジュールの依存関係は含まれません。
次のアーキテクチャのマルチモジュール プロジェクトがあります。
pom.xml (parent pom)
--module_1
----pom.xml
--module_2
----pom.xml
module_2
module_1
pom.xml で宣言されている への依存関係があります。
<groupId>${project.groupId}</groupId>
<artifactId>module_1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
の uber jar を作成したいのですが、次の宣言でmodule_2
を使用します。maven-shade-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
これにより、uber jar が生成されます。
- のすべての依存関係を含む
module_2
- の瓶を含む
module_1
- の依存関係を含まない
module_1
すべての依存関係も含めるように指定する方法はありますmodule_1
か?
私が見つけた解決策は、 を使用しmaven-shade-plugin
て uber jar も作成するmodule_1
ことです。この jar は の uber jar に含まれているため、module_2
機能します。module_1
しかし、依存関係を含まない単純な jar ファイルをリリースできるようにするために、この解決策は避けたいと思います。
そして、 (最終的なjarに含まれるファイルをより適切に制御するために)maven-shade-plugin
ではなくを使用したいmaven-assembly-plugin
@ user2321368 による詳細のリクエストに続いて
Maven バージョン: Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
module_1 の pom.xml にその依存関係を含めます: (スコープとバージョンは、依存関係管理セクションの親 pom で宣言されます)
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>other_module_I_havent_mention</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>other_module_I_havent_mention</artifactId>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
...
</dependencies>