Java Maven - 从 x 管理的版本,重复时省略?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27572760/
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
Maven - version managed from x, omitted for duplicate?
提问by collegian
I am having trouble with understanding what happens in maven dependency tree when it states version managed from x; omitted for duplicate.
当 maven 依赖树声明从 x 管理的版本时,我无法理解它发生了什么;省略重复。
For example, let's assume that I have enterprise-data-2.4
defined in the dependency management section of server-a
.
例如,假设我已经enterprise-data-2.4
在server-a
.
I get the following in the dependency tree of server-a
for one of the dependencies server-b
pulling in enterprise-data-2.4
.
我得到的依赖关系树下面server-a
的依赖关系的一个server-b
拉动enterprise-data-2.4
。
[INFO] +- hello.world.welcome.to:server-b:jar:3.1-SNAPSHOT:runtime
[INFO] | +- (hello.world.where.am: enterprise-data:jar:2.4:runtime - version managed from 3.0; omitted for duplicate)
Assuming server-b
is the only jar pulling in enterprise-data-2.4
, my understanding is that server-a
will always pull in enterprise-data-2.4
here. Is this correct?
假设server-b
是唯一的 jar 拉入enterprise-data-2.4
,我的理解是server-a
将始终拉入enterprise-data-2.4
这里。这样对吗?
I however, have code in server-b
dependent on enterprise-data-3.0
and server-b
has a compile time dependency on enterprise-data-3.0
.
我然而,有代码的server-b
依赖enterprise-data-3.0
和server-b
对编译时依赖enterprise-data-3.0
。
Now, I have a test project, let's say test-b
which tests server-b
jar present inside server-a
project and has a test dependency on enterprise-data-3.0
. These tests directly hit the code present on server-a
.
现在,我有一个测试项目,让我们说项目中存在test-b
哪些测试server-b
jarserver-a
并且对enterprise-data-3.0
. 这些测试直接命中存在于 上的代码server-a
。
When I run my tests in test-b
should I get errors while attempting to access functionality present in enterprise-data-3.0
since it's not being pulled in by server-a
or will it pass because there is a test dependency on enterprise-data-3.0
? It passes currently but I am not sure how a test dependency is sufficient.
当我运行我的测试时,test-b
我是否应该在尝试访问中存在的功能时出错,enterprise-data-3.0
因为它没有被拉入,server-a
或者它会通过,因为存在对enterprise-data-3.0
? 它目前通过了,但我不确定测试依赖是否足够。
Please help me understand.
请帮我理解。
Edit: I am using maven-3
.
编辑:我正在使用maven-3
.
Thanks.
谢谢。
回答by t0mppa
For example, let's assume that I have enterprise-data-2.4defined in the dependency management section of server-a.
例如,假设我在 server-a 的依赖项管理部分定义了Enterprise-data-2.4。
Then you always get 2.4 pulled in, even if there's only JARs depending on 1.8 for instance. Dependency management overrides dependency mediation.
然后你总是得到 2.4,即使只有依赖于 1.8 的 JAR。依赖管理覆盖依赖中介。
Assuming server-bis the only jar pulling in enterprise-data-2.4, my understanding is that server-awill always pull in enterprise-data-2.4here. Is this correct?
假设server-b是唯一拉入enterprise-data-2.4 的罐子,我的理解是server-a将始终在这里拉入Enterprise-data-2.4。这样对吗?
Assuming you have no dependency management, then yes. If there are multiple dependencies that are dependent on different versions, then it's a question of which one (and its transitive dependencies) is loaded first, as per the dependency mediation rules for Maven version > 2.0.9. Others will be: "managed from x and omitted for duplicate".
假设你没有依赖管理,那么是的。如果存在多个依赖于不同版本的依赖项,那么根据 Maven 版本 > 2.0.9 的依赖项中介规则,首先加载哪个(及其传递依赖项)是一个问题。其他将是:“从 x 管理并省略重复”。
When I run my tests in test-bshould I get errors while attempting to access functionality present in enterprise-data-3.0since it's not being pulled in by server-aor will it pass because there is a test dependency on enterprise-data-3.0? It passes currently but I am not sure how a test dependency is sufficient.
当我在test-b 中运行我的测试时,我是否应该在尝试访问企业数据 3.0 中存在的功能时出错,因为它没有被服务器 a拉入,或者它会通过,因为存在对企业数据的测试依赖性- 3.0? 它目前通过了,但我不确定测试依赖是否足够。
If it's pulling the wrong version with incompatible code, yes you will see errors. For Maven 3, defining a test scope dependency with 3.0 and compile scope dependency with 2.4 will mean that Maven overrides the 2.4 and goes with the newer one defined on test scope. See this question and its answersfor more details.
如果它使用不兼容的代码提取错误的版本,是的,您会看到错误。对于 Maven 3,使用 3.0 定义测试范围依赖项并使用 2.4 编译范围依赖项将意味着 Maven 覆盖 2.4 并使用在测试范围上定义的更新范围。有关更多详细信息,请参阅此问题及其答案。
Nevertheless, you can always use dependency management in test-bto fix in the version of each dependency that you want to use.
尽管如此,您始终可以在test-b 中使用依赖项管理来修复您要使用的每个依赖项的版本。