如何在 3rd 方库中查找依赖冲突

How to find dependency conflicts in 3rd party libraries

我正在寻找一种方法来查找第 3 方库中的依赖项冲突。我知道 mvn dependency:tree、它的 -Dverbose-Dincludes 选项。这很好用,但有几个缺点:

Coursier 依赖解析器的 CLI 可以做到这一点。例如。要在 com.bynder:bynder-java-sdk:2.2.8 中查找依赖冲突,您可以使用带有 --conflict 标志的 Coursier 的 resolve 命令:

$ cs resolve --conflicts   com.bynder:bynder-java-sdk:2.2.8 

org.jetbrains.kotlin:kotlin-stdlib-common:1.4.10 was selected, but
  com.squareup.okio:okio:2.8.0 wanted version 1.4.0

io.reactivex.rxjava2:rxjava:2.2.20 was selected, but
  com.squareup.retrofit2:adapter-rxjava2:2.9.0 wanted version 2.0.0

com.squareup.okhttp3:okhttp:4.9.0 was selected, but
  com.squareup.retrofit2:retrofit:2.9.0 wanted version 3.14.9

org.jetbrains.kotlin:kotlin-stdlib:1.4.10 was selected, but
  com.squareup.okio:okio:2.8.0 wanted version 1.4.0

这会输出一个冲突列表,仅此而已。除了元数据外,没有下载任何工件,整个过程非常快。

进一步探讨冲突的地方,例如com.squareup.okhttp3:okhttp来自,可以运行

$ cs resolve com.bynder:bynder-java-sdk:2.2.8 --what-depends-on com.squareup.okhttp3:okhttp
  Result:
└─ com.squareup.okhttp3:okhttp:4.9.0
   ├─ com.squareup.okhttp3:logging-interceptor:4.9.0
   │  └─ com.bynder:bynder-java-sdk:2.2.8
   └─ com.squareup.retrofit2:retrofit:2.9.0 com.squareup.okhttp3:okhttp:3.14.9 -> 4.9.0
      ├─ com.bynder:bynder-java-sdk:2.2.8
      ├─ com.squareup.retrofit2:adapter-rxjava2:2.9.0
      │  └─ com.bynder:bynder-java-sdk:2.2.8
      └─ com.squareup.retrofit2:converter-gson:2.9.0
         └─ com.bynder:bynder-java-sdk:2.2.8

输出是一个反向依赖树,显示依赖于 com.squareup.okhttp3:okhttp 的所有子树。