有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java mavenshadeplugin不包括uber jar中其他模块的依赖项

我的问题摘要:在多模块项目中,一个模块依赖于另一个模块。使用maven-shade-plugin构建此模块的uber jar时,正确地包含了其所有依赖项,但不包括其他模块的依赖项


我有一个多模块项目,具有以下体系结构:

pom.xml (parent pom)
--module_1
----pom.xml
--module_2
----pom.xml

module_2在其pom中声明了对module_1的依赖关系。xml:

<groupId>${project.groupId}</groupId>
<artifactId>module_1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>

我想构建一个module_2的uber jar,并使用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的jar
  • 不包括^{的依赖项

是否有一种方法可以指定同时包含module_1的所有依赖项

我发现的一个解决方案是使用maven-shade-plugin来构建一个module_1的uber jar。因为这个jar包含在module_2的uber jar中,所以它可以工作。但是我希望避免使用这种解决方案,以便能够发布一个简单的module_1jar文件,而不包括它的依赖项

我想使用maven-shade-plugin而不是maven-assembly-plugin(为了更好地控制最终jar中包含的文件)


@user2321368请求提供更多详细信息

maven版本:ApacheMaven 3.0.3(r1075438;2011-02-28 18:31:09+0100)

模块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>

共 (0) 个答案