[英]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.