简体   繁体   English

Maven:如何停止使用旧版本的依赖?

[英]Maven: How to stop using old version of dependency?

In my Java Maven Project I can see the following 2 versions of the one dependency (apache httpcomponents):在我的Java Maven Project中,我可以看到以下 2 个版本的一个依赖项(apache httpcomponents):

在此处输入图像描述

How can I ensure that only the newest version (4.5.2) is used in my project?如何确保在我的项目中只使用最新版本(4.5.2)?

I cannot even find 4.2.1 declared anywhere within my pom.xml files to remove it.我什至在我的pom.xml文件中的任何地方都找不到声明的 4.2.1 来删除它。

There should never be two versions of the same dependency for a given project.对于给定的项目,永远不应该有相同依赖项的两个版本。

So either your IDE shows something wrong here or you did not mvn clean before the build so that old and new dependencies mixed.因此,要么您的 IDE 在这里显示错误,要么您在构建之前没有mvn clean以便新旧依赖项混合。

Maven will always take only one version. Maven 将始终只采用一个版本。 Unfortunately, you cannot tell Maven to take the latest one, but it will always take the nearest one in the dependency tree.不幸的是,您不能告诉 Maven 采用最新的,但它总是会采用依赖关系树中最近的一个。

If you want to set the version for a specific dependency, use <dependencyManagement> .如果要设置特定依赖项的版本,请使用<dependencyManagement>

Based on your screenshot you're using IntelliJ.根据您的屏幕截图,您正在使用 IntelliJ。 And I have to agree that this view is kind of confusing.我不得不同意这种观点有点令人困惑。 In the Project -tab you'll External Libraries which contain all dependencies of all projects in this tab.Project -tab 中,您将看到External Libraries ,其中包含此选项卡中所有项目的所有依赖项。 For that reason dependencies might appear with different versions.因此,依赖项可能会出现在不同的版本中。 In the Maven -tab (right hand side) you can see the dependency-tree per project.Maven -tab(右侧)中,您可以看到每个项目的依赖关系树。 First you'll see the direct dependencies, which you can expand to see the next level of dependencies.首先,您将看到直接依赖项,您可以将其展开以查看下一级依赖项。 AFAIK there's no complete dependency list available in IntelliJ, as one would see with Eclipse. AFAIK 在 IntelliJ 中没有可用的完整依赖项列表,正如 Eclipse 所见。

That's the view of IDE, it shows all the using or used library in your project.这是 IDE 的视图,它显示了您项目中所有使用或使用的库。 Once you point your pom.xml to the new version and rebuild your project, the new version will be used.一旦您将 pom.xml 指向新版本并重建您的项目,将使用新版本。 In Intellj, you can select: Menu -> File -> Invalidate Caches/Restart to update it.在 Intellj 中,您可以 select: Menu -> File -> Invalidate Caches/Restart 来更新它。 If that won't help, start new project from your existing pom.xml file如果这没有帮助,请从您现有的 pom.xml 文件开始新项目

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

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