对于那些想知道如何解决依赖冲突问题的人。
我的依赖:
// Conflicted transitive dependency for androidx.test:monitor
- org.robolectric:robolectric -> androidx.test:monitor:1.2.0 (forced to use 1.1.0)
- androidx.test:core -> androidx.test:monitor:1.1.0
- androidx.test:runner -> androidx.test:monitor:1.1.0
// Conflicted transitive dependency for com.google.guava:listenablefuture
- androidx.test.ext:truth -> androidx.test:monitor:9999.0 (forced to use 1.0)
- androidx.work:work-runtime -> androidx.test:monitor:1.0
决议 1
我最终检查了Required by 和Could not resolve [dependency] 关键字 以确定 和选择 我要包含的版本,例如:androidx.test:monitor:1.1.0 & com.google.guava:listenablefuture:1.0 然后排除 其余部分通过执行以下操作:
androidTestImplementation(org.robolectric:robolectric:4.3.1) {
exclude(group = "androidx.test", module = "monitor")
exclude(group = "com.google.guava", module = "listenablefuture")
}
我强制从org.robolectric:robolectric:4.3.1 中排除androidx.test:module,并使用androidx.test:core 和androix.test:runner 都需要的androidx.test:module:1.1.0。
guavalistener 也一样,我没有使用真相,所以我删除了它,但如果你确实需要它,你可以做同样的事情来排除/选择 必需的依赖项 您想要包含的内容
决议 2
如果您使用 roboelectric,您可能想排除一些依赖项,就像这里从 @finder2 java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class org.apache.maven.artifact.Artifact found in modules maven-ant-tasks-2.1.3.jar 中一样
上述方法是一个修补程序,您也可能需要仔细选择要使用的传递依赖项,或者只是删除不需要的依赖项(truth 是我的示例)
下面是修复findbugs依赖冲突后的错误构建输出,通过上述方法,我能够修复它。
* What went wrong:
Could not determine the dependencies of task ':app:preDevDebugAndroidTestBuild'.
> Could not resolve all task dependencies for configuration ':app:devDebugAndroidTestRuntimeClasspath'.
> Could not resolve androidx.test:monitor:{strictly 1.1.0}.
Required by:
project :app
> Cannot find a version of 'androidx.test:monitor' that satisfies the version constraints:
Dependency path 'android-etalase-app:app:unspecified' --> 'org.robolectric:robolectric:4.3.1' --> 'androidx.test:monitor:1.2.0'
Constraint path 'android-etalase-app:app:unspecified' --> 'androidx.test:monitor:{strictly 1.1.0}' because of the following reason: devDebugRuntimeClasspath uses version 1.1.0
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test:core:1.0.0' --> 'androidx.test:monitor:1.1.0'
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test:runner:1.1.0' --> 'androidx.test:monitor:1.1.0'
Dependency path 'android-etalase-app:app:unspecified' --> 'org.robolectric:robolectric:4.3.1' --> 'org.robolectric:shadows-framework:4.3.1' --> 'androidx.test:monitor:1.2.0'
> Could not resolve androidx.test:monitor:1.2.0.
Required by:
project :app > org.robolectric:robolectric:4.3.1
project :app > org.robolectric:robolectric:4.3.1 > org.robolectric:shadows-framework:4.3.1
> Cannot find a version of 'androidx.test:monitor' that satisfies the version constraints:
Dependency path 'android-etalase-app:app:unspecified' --> 'org.robolectric:robolectric:4.3.1' --> 'androidx.test:monitor:1.2.0'
Constraint path 'android-etalase-app:app:unspecified' --> 'androidx.test:monitor:{strictly 1.1.0}' because of the following reason: devDebugRuntimeClasspath uses version 1.1.0
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test:core:1.0.0' --> 'androidx.test:monitor:1.1.0'
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test:runner:1.1.0' --> 'androidx.test:monitor:1.1.0'
Dependency path 'android-etalase-app:app:unspecified' --> 'org.robolectric:robolectric:4.3.1' --> 'org.robolectric:shadows-framework:4.3.1' --> 'androidx.test:monitor:1.2.0'
> Could not resolve androidx.test:monitor:1.1.0.
Required by:
project :app > androidx.test:core:1.0.0
project :app > androidx.test:runner:1.1.0
> Cannot find a version of 'androidx.test:monitor' that satisfies the version constraints:
Dependency path 'android-etalase-app:app:unspecified' --> 'org.robolectric:robolectric:4.3.1' --> 'androidx.test:monitor:1.2.0'
Constraint path 'android-etalase-app:app:unspecified' --> 'androidx.test:monitor:{strictly 1.1.0}' because of the following reason: devDebugRuntimeClasspath uses version 1.1.0
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test:core:1.0.0' --> 'androidx.test:monitor:1.1.0'
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test:runner:1.1.0' --> 'androidx.test:monitor:1.1.0'
Dependency path 'android-etalase-app:app:unspecified' --> 'org.robolectric:robolectric:4.3.1' --> 'org.robolectric:shadows-framework:4.3.1' --> 'androidx.test:monitor:1.2.0'
> Could not resolve com.google.guava:listenablefuture:1.0.
Required by:
project :app > androidx.work:work-runtime:2.2.0
> Cannot find a version of 'com.google.guava:listenablefuture' that satisfies the version constraints:
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.work:work-runtime:2.2.0' --> 'com.google.guava:listenablefuture:1.0'
Constraint path 'android-etalase-app:app:unspecified' --> 'com.google.guava:listenablefuture:{strictly 1.0}' because of the following reason: devDebugRuntimeClasspath uses version 1.0
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test.ext:truth:1.0.0' --> 'com.google.guava:guava:27.0.1-jre' --> 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
> Could not resolve com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava.
Required by:
project :app > androidx.test.ext:truth:1.0.0 > com.google.guava:guava:27.0.1-jre
> Cannot find a version of 'com.google.guava:listenablefuture' that satisfies the version constraints:
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.work:work-runtime:2.2.0' --> 'com.google.guava:listenablefuture:1.0'
Constraint path 'android-etalase-app:app:unspecified' --> 'com.google.guava:listenablefuture:{strictly 1.0}' because of the following reason: devDebugRuntimeClasspath uses version 1.0
Dependency path 'android-etalase-app:app:unspecified' --> 'androidx.test.ext:truth:1.0.0' --> 'com.google.guava:guava:27.0.1-jre' --> 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'