2

I am trying to figure out why IntelliJ is using the wrong version (8.1.1 instead of 8.1.2) of one of my project's Java files. The IntelliJ project is a maven project with many dependencies.

To debug, I tried to use the following from the command line:

mvn dependency:tree -Dverbose -Dincludes=jaffa-ria

per the documentation on Maven's site. I see a lot of output about downloading, including some for the jaffa-ria package:

Downloaded: https://nexus/content/groups/public/org/jaffa/jaffa-ria/8.1.2-SNAPSHOT/maven-metadata.xml (941 B at 3.2 kB/s)

However, I don't get any dependency tree printed whatsoever. The mvn command completes normally with a BUILD SUCCESS, and I only see one warning:

[WARNING] Using Maven 2 dependency tree to get verbose output,
 which may be inconsistent with actual Maven 3 resolution

What can I do to find the dependency conflict? I am using Apache Maven 3.5.0. and Intellij IDEA Ultimate 2019.1.

kc2001
  • 5,008
  • 4
  • 51
  • 92
  • 1
    Possible duplicate of ["Using Maven 2 dependency tree to get verbose output, which may be inconsistent with actual Maven 3 resolution"](https://stackoverflow.com/questions/29409087/using-maven-2-dependency-tree-to-get-verbose-output-which-may-be-inconsistent) – Tim Biegeleisen Jun 14 '19 at 11:08
  • Please try Googling your error message before asking a question here. – Tim Biegeleisen Jun 14 '19 at 11:09
  • I have googled extensively. I am actually trying to find an any means of solving the dependency problem. I'll rephrase my question. – kc2001 Jun 14 '19 at 11:11

2 Answers2

2

First of all, try dependency:tree without verbose. If this does not work out, you can try to add the "dependency convergence" rule (an enforcer rule).

It will fail if you have conflicting versions of the same dependency and this conflict is not resolved in the dependencyManagement. Furthermore, it shows where the conflicting places come from.

Furthermore, if you just want to fix a given version, you can do so in the dependencyManagement.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Thanks! If I also omit the includes argument, I am now able to see 5 usages of org.jaffa:jaffa-ria:jar:8.1.2-SNAPSHOT. Unfortunately, I don't see any mention of a jaffa-ria 8.1.1. Maybe I need to do some IntelliJ cleanup? – kc2001 Jun 14 '19 at 11:35
  • I am no IntelliJ expert, but it might help. Have you also run `dependency:list` and looked for the version there? – J Fabian Meier Jun 14 '19 at 11:56
  • dependency:list also shows uses of 8.1.2, but not 8.1.1. Thanks to your help with the maven side of things, I'm now thinking that IntelliJ's indexes are confused, despite me having cleared the caches and restarted. – kc2001 Jun 14 '19 at 12:02
  • IntelliJ has nothing to do with `dependency:tree`. You need to install artifacts first, or the Maven will use older ones that are in your repository. – Meo Jun 14 '19 at 12:06
  • @Meo that is not true. Maven will never automatically use older ones because it cannot find the ones it is looking for. – J Fabian Meier Jun 14 '19 at 12:07
  • I am not saying that. If you edit your pom in module A, and then use `dependency:tree` on a module B that has a dependency on A, it will use an older version of A that is in your repository (of the same version, e.g. SNAPSHOT), not the one in your project in IntelliJ. An easy mistake. – Meo Jun 14 '19 at 12:08
  • But IntelliJ being smart, will use the pom in your project for the dependency resolution. So executions by Maven could use one version, IntelliJ another at the same time. – Meo Jun 14 '19 at 12:15
1

Use Maven Helper plugin for IntelliJ or maven-enforcer-plugin with dependencyConvergence rule.

maven-dependency-plugin no longer supports displaying conflicts since version 3.0, and as the warning says, older version may be inconsistent with actual Maven 3 resolution.

Meo
  • 12,020
  • 7
  • 45
  • 52
  • 1
    Thanks. Maven Helper, and my clumsy experimentation with it, solved my problem. Maven Helper was showing dependencies on both 8.1.1 and 8.1.2. I fooled around with the "exclude" menu item and others, and realized that I had inadvertently edited the pom files. After reverting the pom files, refreshing the UI, and reimporting, Maven Helper no longer showed the dependency on 8.1.1. I'm guessing that IntelliJ had cached some old version information, and after reimporting all of the project's maven pom files, everything got reset properly. – kc2001 Jun 14 '19 at 15:04
  • 2
    Looks like maven-dependency-plugin 3.2.0 will support -Dverbose=true and output the missing dependencies https://issues.apache.org/jira/browse/MDEP-644 – Brad Cupit Jan 07 '21 at 20:01