java maven 依赖拉错了依赖
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13635388/
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 dependency pulling a wrong dependency
提问by DarthVader
I have a dependency as follows:
我有如下依赖:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2</version>
<scope>compile</scope>
</dependency>
This is pulling down another dependency httpcore.4.1.4
which throws a ClassDefNotFound, when i deploy httpcore.4.2
everything works.
httpcore.4.1.4
当我部署httpcore.4.2
一切正常时,这会拉低另一个抛出 ClassDefNotFound 的依赖项。
I added both of the dependencies as follows:
我添加了两个依赖项,如下所示:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.2</version>
<scope>compile</scope>
</dependency>
and still facing the same issue ie: mvn brings down httpcore.4.1.2
not httpcore.4.2
并且仍然面临同样的问题,即: mvnhttpcore.4.1.2
不降低httpcore.4.2
how can i resolve this?
我该如何解决这个问题?
EDIT:
编辑:
added;
添加;
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
采纳答案by Tobb
You might have a transitive dependency, one your other dependencies depend on the version you don't want.
您可能有一个传递依赖项,您的其他依赖项取决于您不想要的版本。
To get an overview of all dependencies, direct and transitive, try:
要获得所有依赖项的概述,直接和传递,请尝试:
mvn dependency:tree
mvn 依赖:树
If you find a crash between different versions of the same dependency, the first thing you should do is figure out whether the crash is critical (do you need both?) If not, upgrade so that the lowest dependency version will become equal to the highest. If it is a transitive dependency consider upgrading the version of this.
如果您发现同一依赖项的不同版本之间发生崩溃,您应该做的第一件事是确定崩溃是否严重(您两者都需要吗?)如果不是,请升级以使最低的依赖项版本与最高的版本相等. 如果它是一个传递依赖,考虑升级这个版本。
If you just want to lock on to a specific version of the dependency, you have some choices:
如果您只想锁定依赖项的特定版本,您有一些选择:
Exclude the transitive dependency:
排除传递依赖:
<dependency>
<groupId>com.something</groupId>
<artifactId>something</artifactId>
<exclusions>
<exclusion>
<groupId>com.somethingElse</groupId>
<artifactId>somethingElse</artifactId>
</exclusion>
</exclusions>
</dependency>
Include a specific version:
包括特定版本:
<dependency>
<groupId>com.somethingElse</groupId>
<artifactId>somethingElse</artifactId>
<version>2.0</version>
</dependency>
Any dependency version added explicitly in your pom will override the version of any transitive dependency of the same groupId/artifactId.
在你的 pom 中显式添加的任何依赖版本将覆盖相同 groupId/artifactId 的任何传递依赖的版本。
Although being a bit of a puzzle, you should try to get compatible versions of your dependencies, that being version with the same version transitive dependencies.
尽管有点困惑,但您应该尝试获取依赖项的兼容版本,即具有相同版本传递依赖项的版本。