我已经在 IntelliJ 中建立了一个多模块项目。我的模块结构如下所示:
Project (no pom.xml file)
|
|--moduleA
| |
|
|--moduleB
| |-Log4J
| |-Jackson
|
|--moduleC
| |-moduleA
| |-moduleB
| |-Log4J
|
|--moduleD
| |-moduleC
| |-moduleA
| |-moduleB
| |-Log4J
|
|--moduleE
| |-moduleA
| |-moduleB
| |-moduleC
| |-Log4J
moduleC
依赖于moduleA
和moduleB
,moduleD
依赖于moduleA
, moduleB
和 moduleC
。 moduleE
也是如此。
我想创建两个 Uber jar。一个用于moduleD
,一个用于moduleE
,每个都包含模块的依赖项,包括模块A、B和C。
我正在使用 Maven 3 来管理我的依赖项,并使用 maven-shade-plugin 来创建 Uber jar。
我在 pom.xml
文件中添加了必要的依赖项,如下所示:
<dependency>
<groupId>com.modules</groupId>
<artifactId>moduleA</artifactId>
<version>1.0</version>
</dependency>
并且我已经将 maven-shade-plugin
添加到每个模块的 pom.xml
文件中。到目前为止,我能够为 moduleA
和 moduleB
构建一个 super jar,但是当我尝试 moduleC
时,我收到以下错误:
[WARNING] The POM for com.modules:moduleA:jar:1.0 is missing, no dependency information available
[WARNING] The POM for com.modules:moduleB:jar:1.0 is missing, no dependency information available
我该如何解决?
如果我通过 IntelliJ 构建和运行模块,一切正常。此外,我还能够通过配置 IntellJ Artifact 构建一个 uber jar。
如何配置 Maven 来执行此操作?我需要它,因为我想使用 uber jar 进行生产,并且我正在尝试设置 Jenkins 以在提交后构建解决方案。
我已将以下帖子设为红色:How to create self-containing (standalone) jar of each modules of a multi-module maven project但我无法让它发挥作用。
编辑:
这是moduleA
和moduleB
中的maven-shade-plugin
设置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
这是moduleC
中的maven-shade-plugin
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
如您所见,我使用的是默认配置。
最佳答案
尝试添加
<includes>
<include>**</include>
</includes>
在您定义排除项的同一位置。
唯一出现的 <filter>
我可以找到与包含和排除过滤器结合使用的内容。
不要拖延,但我猜这就是您的构建失败的原因。
关于java - 如何使用来自多个模块的依赖项构建 Uber jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36548967/