android.arch.persistence.room:测试依赖Kotlin?

android.arch.persistence.room:testing depends on Kotlin?

很久以前,我为我的 android 工作室项目启用了 Kotlin 支持,然后将其删除。 Android Studio,hovewer,不停地通知我更新的 kotlin 库版本可用。随便。

我已经关闭了 Kotling 插件,删除了它和 gradle 中的所有 Kotling 配置(而且,如果这意味着什么,所有 .kt 文件也被删除了)

我的项目是在 Java 上编写的,没有任何 Kotlin libs\plugins enbabled\etc。 我正在编写一些 Room 迁移测试并尝试启动它们,但收到的消息是

Conflict with dependency 'org.jetbrains.kotlin:kotlin-stdlib' in project ':my-project'. Resolved versions for app (1.1.2-3) and test app (1.2.41) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.

通过依赖关系树并在新项目中进行测试,我意识到,当我使用

时添加了 kotlin-stdlib 依赖关系
androidTestImplementation 'android.arch.persistence.room:testing:1.1.1'

我发现 android.arch.persistence.room.migration 添加了 kotlin-stdlid 依赖项。 我反编译了那个 jar,发现没有理由包含 kotlin 库。

我仍然忍受所有 Kotlin 的东西只是因为我需要让我的测试工作。

我对此有几个问题:

1) 我可以在没有 kotlin 依赖项的情况下使用 'android.arch.persistence.room:testing:1.1.1' 吗?[​​=14=]

2) 如果 1 个问题的答案是 'No',我可以只使用 kotlin 依赖进行测试吗?

3) 如何删除项目中的旧 kotlin 库 (1.1.2-3)。 gradle 文件或项目中的其他任何地方都没有定义 kotlin 库。

UPD:android依赖项的 kotlin-stlib 输出:

:my-project:androidDependencies
debug
debugCompileClasspath - Dependencies for compilation
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3@jar

debugRuntimeClasspath - Dependencies for runtime/packaging
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3@jar

debugAndroidTest
debugAndroidTestCompileClasspath - Dependencies for compilation
+--- org.jetbrains.kotlin:kotlin-stdlib:1.2.41@jar

debugAndroidTestRuntimeClasspath - Dependencies for runtime/packaging
+--- org.jetbrains.kotlin:kotlin-stdlib:1.2.41@jar

debugUnitTest
debugUnitTestCompileClasspath - Dependencies for compilation
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3@jar

debugUnitTestRuntimeClasspath - Dependencies for runtime/packaging
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3@jar

release
releaseCompileClasspath - Dependencies for compilation
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3@jar

releaseRuntimeClasspath - Dependencies for runtime/packaging
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3@jar

releaseUnitTest
releaseUnitTestCompileClasspath - Dependencies for compilation
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3@jar

releaseUnitTestRuntimeClasspath - Dependencies for runtime/packaging
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3@jar

回答我的问题:

1) 我可以在没有 kotlin 依赖项的情况下使用 'android.arch.persistence.room:testing:1.1.1' 吗?[​​=54=]

没有,因为依赖它。例如,我发现 kotlin.reflect.KDeclarationContainer class 的用法。

2) 如果1个问题的答案是'No',我可以只使用kotlin依赖来测试吗?

,此库仅可用于使用

进行测试
androidTestImplementation 'android.arch.persistence.room:testing:x.x.x'

3) 如何删除项目中的旧 kotlin 库 (1.1.2-3)。 gradle 文件或项目中的其他任何地方都没有定义 kotlin 库。

在我的例子中,这个库是对项目中另一个依赖项的依赖项。

您可以使用

简单地检测所有传递依赖

./gradlew 依赖项

命令或通过 Android Studio GUI 使用

Gradle --> :your-module --> Tasks --> help --> dependencies

我刚刚将这个第三方库更新到最新版本,因此依赖的 kotlin-stlib 版本变得相同。

如果你想强制覆盖使用 kotlin 版本,你可以在模块的 build.gradle:

中执行
// This is example to force using 1.2.41 kotlin version instead of any other **FOR ALL** libraries
   configurations.all {
      resolutionStrategy {
          force 'org.jetbrains.kotlin:kotlin-stdlib:1.2.41'
      }
} 

此外,您可以更精确地排除或强制特定模块依赖的传递依赖。请看:

https://docs.gradle.org/current/userguide/managing_transitive_dependencies.html