1

このようなマルチモジュールプロジェクトがあります

foobar
 |
 +-- pom.xml
 |
 +-- common-lib/
 |       |
 |       +-- pom.xml
 |       +-- src/
 |
 +-- foo-app/
 |       |
 |       +-- pom.xml
 |       +-- src/
 |
 +-- bar-app/
 |       |
 |       +-- pom.xml
 |       +-- src/
 |
-+-

との両方がコードにfoo-app依存し、独自の POM の依存関係にも依存します。bar-appcommon-lib

I を使用しmvn packageて、3 つの軽量 JAR をビルドできます。

私が欲しいのは、それぞれに依存関係が含まれている2つの実行可能なJARです。

  • フーアプリ
  • バーアプリ

Mavenでこれを行うにはどうすればよいですか?


との依存関係が衝突しているため、誰かがそれを提案した場合、foo-appそれらbar-appを 1 つの foobar-app にマージすることはできません。

4

1 に答える 1

1

Add maven assembly plugin to the pom.xml's which you want to create a executable jar with dependencies. Execute mvn package on aggregator pom.xml. This command will execute mvn package command on all the sub modules. The ones that have maven assembly plugin will generate executable jars with dependencies.

In your case add this to foo-app and bar-app projects pom.xml. And configure your <mainClass>your.package.mainclass</mainClass> according to each projects main class.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>your.package.mainclass</mainClass>
                    </manifest>
                </archive>

            </configuration>
            <executions>
                <execution>
                    <id>assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
于 2018-03-07T18:25:00.547 に答える