Ethan Leroy
Ethan Leroy

Reputation: 16534

Maven loads wrong version of dependency

In my maven pom.xml I have the following dependency:

<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>Chart.js</artifactId>
    <version>2.0.2</version>
</dependency>

When I build it, maven loads Version 1.1.1 instead of 2.0.2. I can't explain why this could happen. mvn dependency:tree gives me the following output:

[INFO] my.group:mypackage:war:0.0.1-SNAPSHOT
[INFO] ...
[INFO] +- org.webjars.bower:Chart.js:jar:1.1.1:compile
[INFO] +- org.webjars.bower:angular-chart.js:jar:0.10.2:compile
[INFO] ...

So, Chart.js is a direct dependency of my project and no other dependency depends on Chart.js and forces loading of version 1.1.1. Even when I look at the effective pom in IntelliJ, there is no dependency for version 1.1.1, only my dependency for 2.0.2.

Any idea why maven loads the wrong version?

Upvotes: 11

Views: 13884

Answers (1)

Thomas Betous
Thomas Betous

Reputation: 5123

Your problem is that angular-chart.js:jar:0.10.2 has a dependency to chart.js 1.1.1. You have a conflict here.

Look at this link to see all dependencies: https://mvnrepository.com/artifact/org.webjars.bower/angular-chart.js/0.10.2

You need to add exclusion tags when you add the angular-chart.js dependency:

<dependency>
  <groupId>org.webjars.bower</groupId>
  <artifactId>angular-chart.js</artifactId>
  <version>0.10.2</version>
  <exclusions>
      <exclusion> 
          <groupId>org.webjars.bower</groupId>
          <artifactId>Chart.js</artifactId>
      </exclusion>
  </exclusions>
</dependency>
<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>Chart.js</artifactId>
    <version>2.0.2</version>
</dependency>

Upvotes: 4

Related Questions