Java shade插件生成的dependency-reduced-pom.xml的目的是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22904573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 18:48:52  来源:igfitidea点击:

What is the purpose of dependency-reduced-pom.xml generated by the shade plugin?

javamavenmaven-shade-plugin

提问by Transcendence

I read over the docsand didn't find anything that talks about what it's used for.

我通读了文档并没有找到任何关于它的用途的内容。

回答by Tome

The shade:shade Mojo is quite well documented, here especially about the createDependencyReducedPomparameter, which will create that dependency-reduced-pom.xmlfile: maven-shade-plugin/shade-mojo.html#createDependencyReducedPom

shade:shade Mojo 有很好的文档记录,这里特别是关于createDependencyReducedPom参数,它将创建该dependency-reduced-pom.xml文件:maven-shade-plugin/shade-mojo.html#createDependencyReducedPom

In short, this is quite useful if you intend to use that shaded JAR (instead of the normal JAR) as a dependency for another module. That dependency-reduced-pom.xmlwill not contain the JARs already present in the shaded one, avoiding useless duplication.

简而言之,如果您打算使用着色的 JAR(而不是普通的 JAR)作为另一个模块的依赖项,这将非常有用。这dependency-reduced-pom.xml将不包含阴影中已经存在的 JAR,从而避免无用的重复。

回答by morpheus

I read the docsabout a hundred times or so and still couldn't understand what this is for, what really is the use case for it.

我阅读了大约一百次左右的文档,但仍然无法理解它的用途,它的真正用例是什么。

Finally this is what I think: lets say you have a project with dependencies A, B, C, D, E. In the pom.xmlyou configure the shade plugin in such a way that when it creates the uber-jar (call it foo.jar), it includes A, B, C in the shaded jar but for some reason you decide not to include D, E in the shaded jar even though your project depends on them - a case in point are dependencies that are needed only for testing (e.g. any dependency that has a scopeof testand is not included in the shaded jar). The dependency-reduced-pom.xmlwill define D, E in it. The idea is that if someone wants to use foo.jarthe dependency-reduced-pom.xmlprovides a hint of some sort that beware foo.jaris missing dependencies D, E in it - use at your own risk. You might then decide to explicitly add D, E in the project that will use foo.jar.

最后,这就是我的想法:假设您有一个依赖项 A、B、C、D、E 的项目。在pom.xml您配置 shade 插件时,当它创建 uber-jar(调用它foo.jar)时,它在阴影 jar 中包含 A、B、C 但由于某种原因您决定不将 D、E 包含在阴影 jar 中,即使您的项目依赖于它们 - 一个例子是仅用于测试的依赖项(例如任何依赖项具有scopetest,并且不包括在阴影罩)。在dependency-reduced-pom.xml将它定义d,E。我们的想法是,如果有人想使用foo.jardependency-reduced-pom.xml提供了一些那种提防的暗示foo.jar是缺少依赖d,E在里面-使用您自己的风险。然后,您可能决定在将使用的项目中明确添加 D、Efoo.jar.

So the dependency-reduced-pom.xmlis more like missing-dependencies.xmland lists the dependencies which are missing in the uber-jar which is output by the shade plugin.

所以dependency-reduced-pom.xml更像是missing-dependencies.xml并列出了由 shade 插件输出的 uber-jar 中缺少的依赖项。