繁体   English   中英

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

[英]android.arch.persistence.room:testing depends on Kotlin?

很久以前,我为我的 android studio 项目启用了 Kotlin 支持,然后将其删除。 然而,Android Studio 不会停止通知我有更新的 kotlin libs 版本可用。 任何。

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

我的项目是用 Java 编写的,没有任何 Kotlin 库\\插件启用\\等。 我正在编写一些 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 ”吗?

2) 如果 1 个问题的答案是“否”,我可以将 kotlin 依赖项仅用于测试吗?

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

UPD:androidDependencies 的 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 ”吗?

,因为它依赖于它。 例如,我发现了kotlin.reflect.KDeclarationContainer类的用法。

2) 如果 1 个问题的答案是“否”,我可以将 kotlin 依赖项仅用于测试吗?

是的,此库仅可用于测试使用

androidTestImplementation 'android.arch.persistence.room:testing:x.x.x'

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

就我而言,这个库是项目中另一个依赖项的依赖项。

您可以简单地使用以下方法检测所有传递依赖项

./gradlew 依赖项

命令或通过 Android Studio GUI 使用

Gradle --> :your-module --> 任务 --> 帮助 --> 依赖项

我刚刚将这个第三方库更新到最新版本,因此依赖的 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM