简体   繁体   English

Gradle Kotlin DSL:在唯一位置定义 Android 构建工具版本

[英]Gradle Kotlin DSL: Define Android build tools version in unique place

I am using Android Studio 4.0 and I added buildSrc module in a multi-module project to manage dependency versions.我正在使用 Android Studio 4.0,并在多模块项目中添加了buildSrc模块来管理依赖版本。 Inside buildSrc i have Dependencies object and Version object to use kotlin-dsl in the build.gradle.kts , The problem it's I can't access to Constants object from gradle.kts and I have 2 versions of com.android.tools.build:gradle:4.0.0 and I need this dependency for my custom plugins, How I can have only one version of the buildtools? Inside buildSrc i have Dependencies object and Version object to use kotlin-dsl in the build.gradle.kts , The problem it's I can't access to Constants object from gradle.kts and I have 2 versions of com.android.tools.build:gradle:4.0.0并且我的自定义插件需要此依赖项,我如何只能拥有一个版本的构建工具?

//Dependencies.kt
object PluginDependencies {
 const val buildTools = "com.android.tools.build:gradle:${Versions.buildTools}"
}

//Versions.kt
object Versions {
const val buildTools = "4.0.0" 
}

I have this in my build.gradle.kts我的build.gradle.kts中有这个

plugins {
    `kotlin-dsl`
}
gradlePlugin {
    plugins {
        register("CustomPlugin") {
            id = "customPlugin"
            implementationClass = "CustomPlugin"
        }
    }
}
repositories {
    mavenCentral()
    google()
    jcenter()
}

dependencies {
    // this cuase a compile error -> implementation("com.android.tools.build:gradle:${constants.Versions.buildTools}")
    implementation("com.android.tools.build:gradle:4.0.0")
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72")

    /* Depend on the default Gradle API's since we want to build a custom plugin */
    implementation(gradleApi())
    implementation(localGroovy())
}

You can not use the constant PluginDependencies in your buildSrc/build.gradle.kts file because at this stage the build script isn't aware of your Code which relies in buildSrc/src/main/kotlin/PluginDependencies.kt.您不能在 buildSrc/build.gradle.kts 文件中使用常量 PluginDependencies,因为在此阶段构建脚本不知道依赖于 buildSrc/src/main/kotlin/PluginDependencies.kt 的代码。 The buildSrc/build.gradle.kts file is the first that gets build and after that the rest. buildSrc/build.gradle.kts 文件是第一个被构建的文件,然后是 rest。

This is still true but what you can do is creating a buildSrc within a buildSrc.这仍然是正确的,但您可以做的是在 buildSrc 中创建一个 buildSrc。 I wasn't aware of it but currently found this sample:我不知道,但目前发现了这个样本:

https://github.com/badoo/Reaktive/ https://github.com/badoo/Reaktive/

暂无
暂无

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

相关问题 Android Studio构建工具和Gradle版本兼容性 - Android Studio build tools and gradle version compatibility gradle kotlin-dsl move android {} into subproject {} in root project build.gradle.kts - gradle kotlin-dsl move android {} into subproject {} in root project build.gradle.kts 使用 Kotlin DSL 迁移 Android Gradle 插件 7.0.0 - Android Gradle Plugin 7.0.0 migration with Kotlin DSL 升级的Android Studio - Project不再构建gradle构建工具版本 - Upgraded Android Studio - Project no longer builds gradle build tools version 如何在 Android Studio Bumblebee 中将 build.gradle 从 Groovy 迁移到 Kotlin DSL? - How to Migrate build.gradle from Groovy to Kotlin DSL in Android Studio Bumblebee? “Gradle 同步失败:未找到已安装的构建工具。安装 Android 构建工具版本 19.1.0 或更高版本” - "Gradle sync failed: No installed build tools found. Install the Android build tools version 19.1.0 or higher" 使用 android gradle 插件版本 7.0.0-alpha15 时无法使用 kotlin-gradle-dsl 脚本 - Cannot use kotlin-gradle-dsl scripts while using android gradle plugin version 7.0.0-alpha15 如何使用 Maven-Publish Android Gradle Plugin 生成的组件在 Kotlin DSL (build.gradle.kts) 中? - How do you use Maven-Publish Android Gradle Plugin's generated components in Kotlin DSL (build.gradle.kts)? Android Gradle构建工具DOC - Android Gradle build tools DOC Android Build Tools Gradle 2.3.2 - Android Build Tools Gradle 2.3.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM