0

In my Java Maven Project I can see the following 2 versions of the one dependency (apache httpcomponents):

enter image description here

How can I ensure that only the newest version (4.5.2) is used in my project?

I cannot even find 4.2.1 declared anywhere within my pom.xml files to remove it.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
java12399900
  • 1,485
  • 7
  • 26
  • 56
  • Did you clean and build the project? – Dumidu Udayanga Jul 03 '20 at 09:42
  • 1
    The old version might be transitively pulled in by another dependency. [Inspect the dependency tree](http://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html) to see if that's the case. If it is, you can try [using an exclusion](https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html#dependency-exclusions). – Slaw Jul 03 '20 at 10:11

3 Answers3

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.

Maven will always take only one version. Unfortunately, you cannot tell Maven to take the latest one, but it will always take the nearest one in the dependency tree.

If you want to set the version for a specific dependency, use <dependencyManagement>.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
0

Based on your screenshot you're using 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. For that reason dependencies might appear with different versions. In the Maven-tab (right hand side) you can see the dependency-tree per project. 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.

Robert Scholte
  • 11,889
  • 2
  • 35
  • 44
0

That's the view of IDE, it shows all the using or used library in your project. Once you point your pom.xml to the new version and rebuild your project, the new version will be used. In Intellj, you can select: Menu -> File -> Invalidate Caches/Restart to update it. If that won't help, start new project from your existing pom.xml file

VinhNT
  • 1,091
  • 8
  • 13