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

发布于 2024-12-11 07:30:20 字数 1598 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一抹微笑 2024-12-18 07:30:20

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 run mvn dependency:tree and compare the output with the contents of your zip.

You can try setting the property useTransitiveDependencies to false. This will exclude all transitive dependencies from the zip. But this can have unpleasant side-effects.

轮廓§ 2024-12-18 07:30:20

您使用描述符 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文