kotlin - 在 kotlin 中创建 gradle 插件时如何解决 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。
推荐阅读
- python-3.x - 我需要 python 3 中的 typeError 帮助,我是编码/python 新手,所以我有点困惑
- java - p:fileDownload 的问题(异常)
- javascript - 导入和导出意外令牌导出已安装 babel
- unit-testing - 如何在 ARTOS 中根据平台配置测试框架?
- json - 用未知键操作对象的 jq 程序
- python - 计算一个值在字典中出现的次数?(Python 3)
- hibernate - Hibernate 看不到插入的 sql 脚本数据
- php - Selenium webdriver 自动测试数据 PHP
- sql - 如何关联不直接关联的列?
- python - 一种在numpy中将一个数组映射到另一个数组的方法?