在 kotlin 中创建 gradle 插件时如何解决 kot​​lin 库中的冲突

How to resolve conflict in kotlin libraries when creating gradle plugin in kotlin

尝试使用最新的 kotlin 版本 1.4.21 创建一个插件,因此它与 gradle 中捆绑的 1.3.72 冲突,当我构建它并在下面的日志中抱怨时,有没有办法让我排除gradle?:

中捆绑的 kotlin 库
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    C:/Users/xxx/.gradle/wrapper/dists/gradle-6.7-bin/efvqh8uyq79v2n7rcncuhu9sv/gradle-6.7/lib/kotlin-stdlib-1.3.72.jar (version 1.3)
    C:/Users/xxx/.gradle/wrapper/dists/gradle-6.7-bin/efvqh8uyq79v2n7rcncuhu9sv/gradle-6.7/lib/kotlin-stdlib-common-1.3.72.jar (version 1.3)
    C:/Users/xxx/.gradle/wrapper/dists/gradle-6.7-bin/efvqh8uyq79v2n7rcncuhu9sv/gradle-6.7/lib/kotlin-stdlib-jdk7-1.3.72.jar (version 1.3)
    C:/Users/xxx/.gradle/wrapper/dists/gradle-6.7-bin/efvqh8uyq79v2n7rcncuhu9sv/gradle-6.7/lib/kotlin-stdlib-jdk8-1.3.72.jar (version 1.3)
    C:/Users/xxx/.gradle/wrapper/dists/gradle-6.7-bin/efvqh8uyq79v2n7rcncuhu9sv/gradle-6.7/lib/kotlin-reflect-1.3.72.jar (version 1.3)
    C:/Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.4.21-2/fc405f82531d86896a20e9aab54129dc59f86920/kotlin-stdlib-jdk8-1.4.21-2.jar (version 1.4)
    C:/Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.4.21-2/27a286ba08e5db21b04792befbb584d656e439e7/kotlin-reflect-1.4.21-2.jar (version 1.4)
    C:/Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.4.21-2/813d63537c9df0ee0184f2fada6bc040b1328395/kotlin-stdlib-jdk7-1.4.21-2.jar (version 1.4)
    C:/Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.4.21-2/e9840ab2db3095cf168d5425899be9fc97f848ca/kotlin-stdlib-1.4.21-2.jar (version 1.4)
    C:/Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.4.21-2/3c1c0910bfba8bdb1a14303002d162b96a3aad11/kotlin-stdlib-common-1.4.21-2.jar (version 1.4)
w: Consider providing an explicit dependency on kotlin-reflect 1.4 to prevent strange errors
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath

我的build.gradle.kt:

plugins {
    kotlin("jvm") version "1.4.21-2"
    `java-gradle-plugin`
    `maven-publish`
}

dependencies {
    compileOnly(kotlin("stdlib-jdk8"))
    compileOnly(kotlin("reflect"))
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
    testImplementation("org.junit.jupiter:junit-jupiter-engine:5.7.0")
}

repositories {
    mavenCentral()
    jcenter()
}

gradlePlugin {
    plugins {
        create("changed.this.for.this.post") {
            id = "changed.this.for.this.post"
            implementationClass = "changed.this.for.this.post.MyPlugin"
            version = project.version
        }
    }
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java) {
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

你应该使用 Gradle 6.8,它包括 Kotlin 1.4.20。