Reputation: 1681
In my Java Maven Project
I can see the following 2 versions of the one dependency (apache httpcomponents):
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.
Upvotes: 2
Views: 6523
Reputation: 1101
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
Upvotes: 0
Reputation: 12345
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.
Upvotes: 1
Reputation: 35893
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>
.
Upvotes: 2