Maven程序集在ZIP中包含太多依赖项

时间:2011-10-21 09:05:33

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

我有一个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,很多弹簧罐,旅行车罐......等等。

但我们不想包含这些罐子,只是运行时必需的罐子。我们怎么做呢?

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:0)

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

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

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

相关问题