0

I have parent pom with such config:

<dependencyManagement>  
    <dependencies>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.2.9</version>
        </dependency>
    </dependencies>
</dependencyManagement>

And my child pom:

<dependencies>
    <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.5</version>
    </dependency>
</dependencies>

I want to use 4.3.5 version in my classpath, because at the moment I am getting error, parent version should not be modified:

java.lang.NoClassDefFoundError: org/apache/http/impl/client/HttpClients

Any ideas how to prevent from overriding that 4.2.9 version?

elkoo
  • 704
  • 9
  • 23
  • 1
    "I want to use 4.3.5 version in my classpath, because at the moment I am getting error, parent version should not be modified:" - this somehow contradicts itself. – Smutje Sep 09 '14 at 12:33
  • There is no reason why you would want to have the same dependency with different versions in one modular project. Even if you solve it now it WILL bite you later. Also, that error is caused by NOT using 4.3.5 version in whatever you're running. – Deltharis Sep 09 '14 at 12:36
  • try adding provided for the dependency in the parent pom file – jos Sep 09 '14 at 12:39
  • Your question is a bit confusing - you "want to use 4.3.5" but you want to "prevent from overriding that 4.2.9 version"? Which version do you want the child pom to use? Either way does this question help? http://stackoverflow.com/q/14521176/1570834 – DB5 Sep 09 '14 at 12:55
  • @DB5 I want to use only child version. Yes, I saw this answer, but did not work. – elkoo Sep 09 '14 at 13:00

3 Answers3

0

As you know that your parent pom dependency is include in the child pom then don't need to write dependency in the child pom.xml . To include the parent pom dependency in child use

<dependency>
            <groupId>${defined groupId of parent}</groupId>
            <artifactId>${artifact defined for parent }</artifactId>
            <version>${version defined for parent}</version>
        </dependency>
RSCode
  • 1,573
  • 2
  • 13
  • 21
0

In your parent Pom file for the specified Dependency add scope as Provided

<dependencyManagement>  
    <dependencies>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.2.9</version>
            <scope>provided</scope> 
        </dependency>
    </dependencies>
</dependencyManagement>

But As @Deltharis commented better to use the dependency only in the parent POM

jos
  • 1,082
  • 5
  • 19
  • 45
0

I changed parent version to desired and removed dependency from child (the simple and the best solution). Thanks goues to @Deltharis for the comments!

elkoo
  • 704
  • 9
  • 23