Maven 程序集 在 ZIP 中包含太多依赖项
我有一个 Maven 多模块项目。在一个模块中,我们使用 maven-assemble-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,。 ..ETC。
但我们不想包含这些 jar,而这正是运行时所必需的。我们怎样才能做到呢?
I have a Maven multi-module project. In one module, we create a ZIP with maven-assembly-plugin plugin. The configuration for this:
<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>
And the pom config for this:
<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>
Unfortunately the created ZIP contains much more jar-s, that we would like... for example: 37 X maven-XXX JAR, a lot of spring jars, wagon jars,...etc.
But we wouldn't like to include these jars, just which necessary for runtime. How can we do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Maven 程序集插件仅包含根据您的配置位于
运行时
范围内的jar。您可以运行mvn dependency:tree
并将输出与 zip 的内容进行比较。您可以尝试将属性
useTransitiveDependencies
设置为false
。这将从 zip 中排除所有传递依赖项。但这可能会产生令人不快的副作用。Maven assembly plugin includes only the jars which are in
runtime
scope as per your configuration. You can runmvn dependency:tree
and compare the output with the contents of your zip.You can try setting the property
useTransitiveDependencies
tofalse
. This will exclude all transitive dependencies from the zip. But this can have unpleasant side-effects.您使用描述符
test-service-client-with-dependency.xml
,其中包括结果中的所有内容和厨房水槽。请改用
jar-with-dependencies
。这将包括入口运行时依赖项(本地和瞬态)。如果这仍然太多,那么您可以通过将它们声明为
provided
来省略依赖项(如果其他人稍后会将它们添加到类路径中),< scope>test
(如果依赖项仅是运行测试所必需的)或true
如果这是可选的依赖项。You use the descriptor
test-service-client-with-dependencies.xml
which includes everything and the kitchen sink in the result.Use
jar-with-dependencies
instead. That will include entry runtime dependencies (local and transient).If that is still too much, then you can omit dependencies by declaring them as
<scope>provided</scope>
(if someone else will add them to the classpath later),<scope>test</scope>
(if the dependency is only necessary to run the tests) or<optional>true</optional>
if this is an optional dependency.