11

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?

Ethan Leroy
  • 15,804
  • 9
  • 41
  • 63
  • It shouldn't be happening, so I would do a couple of sanity checks, e.g., check if you have dependency management section, check if you have a parent and it has dependency management section, try specifying version via fixed range `[2.0.2]`. – Anton Koscejev Jul 01 '16 at 07:41
  • I just add it to a sample project and got `2.0.2` correctly, using maven `3.3.9`. its pom file also looks fine. Are you sure you didn't check on the wrong pom? – A_Di-Matteo Jul 01 '16 at 07:42
  • I already checked all that. I never had such a problem before. And I'm working with maven for years now. – Ethan Leroy Jul 01 '16 at 07:43
  • Thanks for your test with the sample project. I'm also on Maven 3.3.9. – Ethan Leroy Jul 01 '16 at 07:45
  • Can you show us all your pom.xml, where does come from angular-chart-js.jar ? – Thomas Betous Jul 01 '16 at 07:47
  • 1
    Please post a full output of `mvn dependency:tree` and not only excerpts..Also the full pom file... – khmarbaise Jul 01 '16 at 07:47

1 Answers1

4

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>
Zoe
  • 27,060
  • 21
  • 118
  • 148
Thomas Betous
  • 4,633
  • 2
  • 24
  • 45
  • But `mvn dependency:tree` does not show the dependency to me. – Ethan Leroy Jul 01 '16 at 07:54
  • How did you put your command. Did you try what maven recommends : http://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html . – Thomas Betous Jul 01 '16 at 07:56
  • Thank you. That fixed it. But I find it really strange that `mvn dependency:tree` does not show dependencies of dependencies even if they overrule my own dependencies. – Ethan Leroy Jul 01 '16 at 07:58
  • 3
    Unfortunately `dependency:tree` shows how dependency is first added, not how its version is finally determined. There are other tools for that, however. For example, in IntelliJ IDEA you can see a dependency graph showing which dependencies were suppressed as duplicates and such. – Anton Koscejev Jul 01 '16 at 08:02
  • 1
    @AntonKoscejev how to see which version finally determined? – alex Feb 06 '22 at 18:48