警告“Kotlin 插件版本与库版本不同";(但它是!) [英] Warning "Kotlin plugin version is not the same as library version" (but it is!)

查看:118
本文介绍了警告“Kotlin 插件版本与库版本不同";(但它是!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Android Studio 项目,我在其中添加了一个 Java 库模块,我称之为 core.我的三个 Gradle 构建文件如下所示.

I have an Android studio project in which I have added a Java library module, which I call core. My three Gradle build files look like this.

project/build.gradle

project/build.gradle

buildscript {
    ext.kotlin_version = '1.2.40'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

core/build.gradle

core/build.gradle

apply plugin: 'java-library'
apply plugin: 'kotlin'

dependencies { 
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7"
    ...
}

app/build.gradle

app/build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android { ... }

dependencies {
    implementation project(':core')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:appcompat-v7:27.1.1'

    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    testImplementation 'junit:junit:4.12'
}

我遇到的问题是,在 core/build.gradle 中,kotlin-stdlib-jdk7 行给了我警告 Plugin version (1.2.40) 与库版本 (jdk7-1.2.40) 不同.我尝试将其更改为:

The problem I have is that, in core/build.gradle, the kotlin-stdlib-jdk7 line is giving me the warning Plugin version (1.2.40) is not the same as library version (jdk7-1.2.40). I have tried changing it to:

实现org.jetbrains.kotlin:kotlin-stdlib"

实现org.jetbrains.kotlin:kotlin-stdlib:1.2.40"

实现org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.40"

实现org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

实现org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

但是警告仍然存在.构建仍然成功运行,我知道我可以毫无问题地压制警告并忽略它,但我真的很想知道为什么会发生这种情况以及如何摆脱它.我正在使用 Android Studio 3.0.1.有没有人知道解决这个问题的方法?

But the warning is still there. The build still runs successfully, and I know I can surpress the warning without any problems and ignore it, but I really want to know why this is happening and how I can get rid of it. I am using Android Studio 3.0.1. Does anyone know of a solution to this?

推荐答案

Kotlin 1.4 默认添加对标准库的依赖:

Starting from Kotlin 1.4 dependency on the standard library added by default:

您不再需要在任何 Kotlin Gradle 项目(包括多平台项目)中声明对 stdlib 库的依赖.默认添加依赖.

You no longer need to declare a dependency on the stdlib library in any Kotlin Gradle project, including a multiplatform one. The dependency is added by default.

自动添加的标准库将与 Kotlin Gradle 插件的版本相同,因为它们具有相同的版本.

The automatically added standard library will be the same version of the Kotlin Gradle plugin, since they have the same versioning.

对于特定于平台的源集,使用相应的特定于平台的库变体,而在其余部分中添加了一个通用标准库.Kotlin Gradle 插件将根据 Gradle 构建脚本的 kotlinOptions.jvmTarget 编译器选项选择合适的 JVM 标准库.

For platform-specific source sets, the corresponding platform-specific variant of the library is used, while a common standard library is added to the rest. The Kotlin Gradle plugin will select the appropriate JVM standard library depending on the kotlinOptions.jvmTarget compiler option of your Gradle build script.

链接到 Kotlin Gradle 插件文档.

Link to Kotlin Gradle plugin documentation.

这篇关于警告“Kotlin 插件版本与库版本不同";(但它是!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆