【问题标题】:Maven assembly Include too many dependencies in a ZIPMaven 程序集在 ZIP 中包含太多依赖项
【发布时间】:2011-12-12 10:21:41
【问题描述】:

我有一个 Maven 多模块项目。在一个模块中,我们使用 maven-assembly-plugin 插件创建了一个 ZIP。这个配置:

<baseDirectory>/</baseDirectory>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
        <outputDirectory>/</outputDirectory>    
        <useProjectArtifact>true</useProjectArtifact>           
        <excludes>
            <exclude>
                com.sample.blabla:test-core-client
            </exclude>
        </excludes>
        <scope>runtime</scope>
    </dependencySet>
  </dependencySets>

以及为此的 pom 配置:

<execution>
    <id>make-service-client-with-dependencies-zip</id>
    <phase>package</phase>
    <goals>
        <goal>single</goal>
    </goals>
    <configuration>
        <finalName>${service-client-with-dependencies.zip.filename}</finalName>
            <appendAssemblyId>true</appendAssemblyId>
        <outputDirectory>${project.build.directory}/zip</outputDirectory>
        <descriptors>
            <descriptor>src/main/assembly/test-service-client-with-dependencies.xml</descriptor>
        </descriptors>
    </configuration>
</execution>

不幸的是,创建的 ZIP 包含更多的 jar-s,我们希望...例如:37 X maven-XXX JAR、很多 spring jar、wagon jar...等等。

但我们不希望包含这些 jar,它们只是运行时所必需的。我们该怎么做?

【问题讨论】:

    标签: maven build maven-plugin maven-assembly-plugin


    【解决方案1】:

    Maven 程序集插件只包含根据您的配置在runtime 范围内的 jar。您可以运行 mvn dependency:tree 并将输出与 zip 的内容进行比较。

    您可以尝试将属性useTransitiveDependencies 设置为false。这将从 zip 中排除所有传递依赖项。但这可能会产生令人不快的副作用。

    【讨论】:

    • 谢谢! false 解决了我的问题。
    • 嘿@Raghuram,将useTransitiveDependencies 设置为false 的这些令人不快的副作用是什么?
    【解决方案2】:

    您使用描述符test-service-client-with-dependencies.xml,其中包括结果中的所有内容和厨房水槽。

    请改用jar-with-dependencies。这将包括入口运行时依赖项(本地和瞬态)。

    如果这仍然太多,那么您可以通过将它们声明为&lt;scope&gt;provided&lt;/scope&gt;(如果其他人稍后将它们添加到类路径中)、&lt;scope&gt;test&lt;/scope&gt;(如果该依赖项只需要运行测试)来省略依赖项或者 &lt;optional&gt;true&lt;/optional&gt; 如果这是一个可选的依赖项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-23
      • 2015-03-29
      • 2011-02-11
      相关资源
      最近更新 更多