Override third-party jar dependencies in maven

Similarly, org.carrot2 depends on commons-httpclient 3.1 So, how can I change this commons-httpclient 3.1 to HttpClient 4.1.1 . I work in an eclipse. How I want to remove commons-httpclient:3.1 from those that depend on this jar file, and I want to replace it with HttpClient 4.1.1 .

So what I was trying to do. I double clicked on this org.carrot2 from the dependency hierarchy folder and went into the pom.xml file and tried to change commons-httpclient 3.1 to httpclient 4.1.1, but this does not allow me to change, since backspace and delete do not work on this.

Any suggestions would be appreciated.

+7
source share
3 answers

First, make sure that the artifact mentioned can work correctly with HttpClient 4.1.1.

We can define an โ€œexceptionโ€ for each dependency, as indicated at http://maven.apache.org/pom.html#Exclusions

The exceptions explicitly tell Maven that you do not want to include the specified project, which is a dependency of this dependency (in other words, its transitive dependency)

exceptions . Exceptions contain one or more exception elements, each containing the group Id and artifactId denoting the dependency for the exception. Unlike the optional one, which may or may not be installed and used, exceptions are actively removed from the Dependency Tree.

 <dependencies> <dependency> <groupId>the_group</groupId> <artifactId>the_artifact</artifactId> <version>the_version</version> <exclusions> <exclusion> <groupId>the_apache_group</groupId> <artifactId>the_http_client_artifact</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>the_apache_group</groupId> <artifactId>the_http_client_artifact</artifactId> <version>4.1.1</version> </dependency> ... </dependencies> 

I hope this can help achieve this requirement.

Hi,

Charlee ch.

+13
source

Add the dependency on HttpClient 4.1.1 to your POM. Maven recognizes the conflict (assuming that groupId and artifactId from httpclient haven't changed) between your direct dependency and indirect dependency and use a newer version. (not because it is newer, but because it is more direct)

And it makes sense that you cannot edit other people's pom files - in the end, you want the carrots to use the new http client only in your program, and not in all programs that use carrots ...

+2
source

If something depends on HttpClient 3.x, this will not work to replace 4.x, since they are completely different APIs. You will get runtime errors when trying to access code that relies on 3.x.

0
source

All Articles