我使用 Gradle Kotlin DSL,在我的项目中我有单独的 build-dependencies
settings.gradle.kts
中包含的 gradle 模块像这样:
pluginManagement {
repositories {
google()
jcenter()
gradlePluginPortal()
}
}
includeBuild("build-dependencies")
该模块包含空插件实现和Deps
目的。其build.gradle.kts
以下:repositories {
google()
jcenter()
gradlePluginPortal()
}
plugins {
`kotlin-dsl`
`java-gradle-plugin`
}
gradlePlugin {
plugins.register("com.example.dependencies") {
id = "com.example.dependencies"
implementationClass = "com.example.dependencies.DependenciesPlugin"
}
}
部门对象:object Deps {
const val buildTools = "com.android.tools.build:gradle:4.1.1"
// more dependencies
}
我想用这个Deps
通过应用 build.gradle.kts
中的插件在所有模块中添加对象文件。plugins {
id("com.example.dependencies")
}
而且效果很好,可以导入使用Deps
目的。但是当我想在根项目中使用它时出现问题
build.gradle.kts
更准确地说是在 buildscript 中,如下所示:buildscript {
repositories {
google()
jcenter()
}
plugins {
id("com.example.dependencies")
}
dependencies {
classpath(com.example.dependencies.Deps.buildTools) // It doesn't work
}
}
有什么方法可以像这样在 buildscript 中使用自定义插件,或者你能建议一些东西来代替这种方法吗?
最佳答案
我也想知道这一点。但是,我认为这是 includeBuild 和 buildSrc 之间的区别。
关于android - 在根项目 buildscript 中使用复合构建中的 Gradle 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65294187/