简体   繁体   English

Maven 拉取比 pom.xml 中指定的旧版本

[英]Maven pulling in older version than specified in pom.xml

I have an existing Project X that I'm adding the AWS SDK to, but for some reason it tries to use an old version of Apache Commons httpclient and blows up.我有一个现有的项目 X,我正在向其中添加 AWS 开发工具包,但由于某种原因,它尝试使用旧版本的 Apache Commons httpclient并失败了。

Project X already required httpclient in its pom.xml without a version, and the AWS SDK v1.11.52 specifies httpclient v4.5.2 as a dependency.项目 X 在其pom.xml已经要求httpclient没有版本,并且 AWS SDK v1.11.52 指定httpclient v4.5.2 作为依赖项。 Since there was no version I set the version as 4.5.2 in Project X's pom.xml .由于没有版本,我在 Project X 的pom.xml中将版本设置为 4.5.2。 This compiles successfully, but when I try to use the code in a JSP page hosted by Tomcat I get this error:这编译成功,但是当我尝试在 Tomcat 托管的 JSP 页面中使用代码时,我收到此错误:

HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.apache.http.conn.ssl.SSLConnectionSocketFactory.<init>(Ljavax/net/ssl/SSLContext;Ljavax/net/ssl/HostnameVerifier;)V

Looking at the lib directory in Tomcat, I see the jar for httpclient v4.3 is there.查看Tomcat中的lib目录,我看到httpclient v4.3的jar在那里。 I confirmed the constructor in the error doesn't exist in v4.3, but does exist in v4.5.2.我确认错误中的构造函数在 v4.3 中不存在,但在 v4.5.2 中确实存在。

I made sure to use mvn clean , clear my classpath file, and also tried deleting ~/.m2 , but when I rebuild the project, v4.3 of httpclient is still pulled in. I am not using an IDE, just Maven.我确保使用mvn clean ,清除我的类路径文件,并尝试删除~/.m2 ,但是当我重建项目时, httpclient v4.3 仍然被拉进来。我没有使用 IDE,只是 Maven。 I have checked the project to make sure there's no mention of v4.3 anywhere so I don't understand why this is happening.我已经检查了该项目以确保在任何地方都没有提到 v4.3,所以我不明白为什么会发生这种情况。

I checked my dependency information with mvn depdency:tree -Dverbose .我用mvn depdency:tree -Dverbose检查了我的依赖信息。 Here is the relevant portion, httpclient is not mentioned anywhere else:这是相关部分,其他地方没有提到httpclient

[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.3:compile (version managed from 4.4.4)
[INFO] |  +- commons-logging:commons-logging:jar:1.1.3:compile (version managed from 1.2)
[INFO] |  \- commons-codec:commons-codec:jar:1.9:compile
...
[INFO] |  +- com.amazonaws:aws-java-sdk-core:jar:1.11.52:compile
[INFO] |  |  +- (commons-logging:commons-logging:jar:1.1.3:compile - version managed from 1.2; omitted for duplicate)
[INFO] |  |  +- (org.apache.httpcomponents:httpclient:jar:4.3:compile - version managed from 4.5.2; omitted for conflict with 4.5.2)

Why is a version not mentioned in any of my pom.xml files being pulled in?为什么我的任何pom.xml文件中都没有提到一个版本被拉入? Can I get maven to explain version managed in more detail?我可以让 maven 更详细地解释version managed吗? Most importantly, is there a way I can force the version number of my dependency?最重要的是,有没有办法强制我的依赖项的版本号?


Update: The issue was that the old version was included in the parent pom;更新:问题是旧版本包含在父 pom 中; I missed this and couldn't figure it out from the dependency:tree output.我错过了这个并且无法从dependency:tree输出中弄清楚。 Updating the parent pom solved the issue.更新父 pom 解决了这个问题。 Sorry for the false alarm.抱歉误报。

If there is no direct dependency, but there are only indirect dependencies, Maven will choose the first it finds, and that purely depends on the order of your complete dependency tree.如果没有直接依赖,只有间接依赖,Maven 会选择它找到的第一个,这完全取决于你的完整依赖树的顺序。 You can force the version to be the one you want, by:您可以通过以下方式强制版本成为您想要的版本:

Side note: Maybe you want to update versions of some indirect dependencies of httpclient as well the same way if you bump into other problems.旁注:如果遇到其他问题,也许您想以同样的方式更新 httpclient 的某些间接依赖项的版本。

If you want to read more, pls have a look at this post.如果你想阅读更多,请看看这篇文章。 A LOT of information is explained here: How do I tell Maven to use the latest version of a dependency?这里解释了很多信息: How do I tell Maven to use the latest version of a dependency?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM