java - 如何使用来自多个模块的依赖项构建 Uber jar

标签 java maven intellij-idea jenkins jar

我已经在 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 依赖于moduleAmoduleBmoduleD 依赖于moduleA , moduleBmoduleCmoduleE 也是如此。

我想创建两个 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 文件中。到目前为止,我能够为 moduleAmoduleB 构建一个 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但我无法让它发挥作用。


编辑:

这是moduleAmoduleB中的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/

相关文章:

java - 没有导入 MAVEN 项目 IntelliJ Idea 的选项

java - Intellij Idea如何切换到其他git账号

java - 如何使用 "extend"类在 Android 中使用 "base"PreferenceActivity 类?

java - 返回到 First/Main Activity 而不重新加载它

java - 在 Spring Boot 中设置 eureka 服务器时出错

postgresql - 使用 Liquibase 的更新目标

android - 在 Intellij Genymotion 插件上运行 Android 应用程序时失败 [INSTALL_FAILED_DEXOPT]

java - 如何让 main 方法等待 Swing 计时器完成执行?

Java 图形只覆盖新形状?

java - 在 Tomcat 中部署的问题