7

Like this org.carrot2 is depending on commons-httpclient 3.1 So how I can change this commons-httpclient 3.1 to HttpClient 4.1.1. I am working in eclipse. As I want to remove commons-httpclient:3.1 from those who are depending on this jar file and I want to replace with HttpClient 4.1.1.

So what I was trying to do.. I doubled click on this org.carrot2 from dependency hierarchy folder and went into its pom.xml file and was trying to change commons-httpclient 3.1 to httpclient 4.1.1 but it is not allowing me to change as backspace and delete is not working on that..

Any suggestions will be appreciated..

thekbb
  • 7,668
  • 1
  • 36
  • 61
arsenal
  • 23,366
  • 85
  • 225
  • 331

3 Answers3

14

Firstly please ensure that the mentioned artifact can work properly with the HttpClient 4.1.1.

We can define "the exclusion" for each dependency as it is mentioned at http://maven.apache.org/pom.html#Exclusions

Exclusions explicitly tell Maven that you don't want to include the specified project that is a dependency of this dependency (in other words, its transitive dependency)

exclusions: Exclusions contain one or more exclusion elements, each containing a groupId and artifactId denoting a dependency to exclude. Unlike optional, which may or may not be installed and used, exclusions actively remove themselves 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 may help to achieve the requirement.

Regards,

Charlee Ch.

Charlee Chitsuk
  • 8,847
  • 2
  • 56
  • 71
  • Chitsuk, thanks for replying..` org.apache.solrsolr-solrj3.2.0 commons-httpclientcommons-httpclient org.apache.httpcomponents httpclient4.1.1 ` so in this I am removing commonshttpclient to httpclient4.1.1 as a dependency of org.apache.solr right?? – arsenal Jul 01 '11 at 17:06
  • Yes, you're correct. The HttpClient 4.1.1 will be used instead. – Charlee Chitsuk Jul 01 '11 at 17:25
  • Chitsuk, and I have already dependencies tag in my pom.xml so I should copy only this ` org.apache.solrsolr-solrj3.2.0 commons-httpclientcommons-httpclient org.apache.httpcomponents httpclient4.1.1 ` right? – arsenal Jul 01 '11 at 17:26
  • Chitsuk, it will automatically build everything as soon as I save it. Or I have to do something..?? – arsenal Jul 01 '11 at 17:33
2

Add a dependency on HttpClient 4.1.1 to your POM. Maven will recognize the conflict (assuming groupId and artifactId of httpclient have not changed) between your direct dependency, and the indirect dependency, and use the newer version. (not because its the newer one, but because it is the more direct one)

And it makes sense you can't edit other people's pom files - after all, you want carrot to use the newer http client only in your program, not in all programs that use carrot ...

meriton
  • 68,356
  • 14
  • 108
  • 175
  • @meriton, how I can add dependencies on HttpClient 4.1.1.. As I want `org.carrot2` to depend on `HttpClient 4.1.1` not on `commons-httpclient 3.1`. – arsenal Jun 30 '11 at 23:33
  • It doesn't matter whether your pom declares the dependency on httpclient or carrot's does, it all ends up in the same classpath. And I trust you know how to add a dependency, since carrot ended up in your dependency hierarchy somehow ... – meriton Jun 30 '11 at 23:36
  • 1
    @meriton, m working on some else projects, he left this project as it is.. so that's why I have to complete this.. And I added this ` org.apache.httpcomponents httpclient 4.1.1 ` in my pom.xml file but those who are depending on `commons-httpclient 3.1` are still depending on this.. – arsenal Jun 30 '11 at 23:39
  • There is a problem with the answer above - Maven will not end up using the newest dependency. Instead, it will resolve the conflict between the 2 dependencies based on smallest distance, so it will choose the one you declare locally in your own pom because it's closer than the other one. – Eugen Jul 01 '11 at 12:01
  • @Eugen, thanks for replying..` org.apache.solrsolr-solrj3.2.0 commons-httpclientcommons-httpclient org.apache.httpcomponents httpclient4.1.1 ` so in this I am removing commonshttpclient to httpclient4.1.1 as a dependency of org.apache.solr right?? – arsenal Jul 01 '11 at 17:19
  • @Eugen: I know that. I didn't say the newness was the reason why it was chosen, only that the newest was chosen. But you are right that somebody might misinterpret it, and I have therefore added a clarification. – meriton Jul 01 '11 at 19:03
0

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

Haroldo Gondim
  • 7,725
  • 9
  • 43
  • 62
laz
  • 28,320
  • 5
  • 53
  • 50
  • hope you remember me.. As per your suggestions I started working using HttpClient 4.1.1, and I am getting new error. [link](http://stackoverflow.com/questions/6551774/http-1-1-401-authorization-required-with-httpclient-4-1-1) – arsenal Jul 01 '11 at 22:34
  • This might be appreciated as a comment, but it is not an answer to op's question. – Madbreaks Jun 27 '18 at 19:31