gradle - 如何为 buildSrc 和应用程序模块定义 Kotlin 版本?

标签 gradle kotlin build.gradle multi-module gradle-kotlin-dsl

我正在使用 buildSrc多模块 Kotlin 项目中的模块到 manage dependency definitions and versions .该模块使用kotlin-dsl如build.gradle.kts所示:

plugins {
    `kotlin-dsl`
}

替代声明:
plugins {
    id("org.gradle.kotlin.kotlin-dsl") version "0.16.2"
}

我想使用相同的 Kotlin 版本来编译 buildSrc模块以及应用程序模块内。我的第一次尝试是简单地添加 JVM 工件:
plugins {
    `kotlin-dsl`
    kotlin("jvm") version "1.2.31"
}

然而,这会导致构建错误,已讨论 here :

Error resolving plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.2.31']
Plugin request for plugin already on the classpath must not include a version



有什么方便的方法只能定义一次整个项目使用的 Kotlin 版本?

有关的
  • Gradle Kotlin DSL: Define Kotlin version in unique place
  • Kotlin versions and the Gradle Kotlin DSL
  • Sample project: Multi-kotlin-project-with-buildSrc
  • 最佳答案

    Each Gradle release is meant to be used with a specific version of the kotlin-dsl plugin and compatibility between arbitrary Gradle releases and kotlin-dsl plugin versions is not guaranteed.

    Using an unexpected version of the kotlin-dsl plugin in a build can cause hard to diagnose problems.

    Starting with Gradle 5.4, a warning is emitted whenever an unexpected version of the kotlin-dsl plugin is detected.



    Paul Merlin @eskatos, 25.04.2019

    因此,我已删除 version :
    plugins {
        `kotlin-dsl`
    }
    
    repositories {
        mavenCentral()
    }
    

    关于gradle - 如何为 buildSrc 和应用程序模块定义 Kotlin 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49522180/

    相关文章:

    android - zip.ZipException : duplicate entry: annotations/Beta. 类

    android - Gradle Build运行时间过长

    kotlin - Kotlin 中 eval 关键字的使用

    android - Android Studio 3.0 Beta4 上的 Dex 错误

    java - Corda jar 启动 : Address already in use: bind error

    android - RecyclerView 适配器中的导航组件

    java - Gradle构建错误Error converting bytecode to dex :Cause: com. android.dex.DexException:Multiple dex files define Landroid/arch/lifecycle/liveData$1

    android - 无法更改依赖配置的解析策略,更新到 'com.android.tools.build:gradle:4.1.0'后

    Android:使用 junit 4.13 时 Unresolved reference

    java - 处理 JAR 和直接 RUN 的资源路径的最佳实践