android - 在根项目 buildscript 中使用复合构建中的 Gradle 插件

标签 android gradle gradle-plugin gradle-kotlin-dsl

我使用 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/

相关文章:

android - 是否有适用于 android 的 gradle 的 aspectj-maven-plugin 的等价物?

android - 在不使用 webview 的情况下在 android 的 textview 中显示 html 表

android - 显示针对空 SearchView 的建议

gradle - 控制台窗口中的 Intellij 插件开发打印

android - 将项目迁移到新的实验性 gradle 插件

android - NDK22 升级后,构建失败并出现 "cannot open crtbegin_so.o/crtend_so.o"错误

android - 项目上方文件夹中的 gradle 依赖项

android - 为旧版 Android 开发

gradle - 如何将Jacoco插件与Gradle集成?

android - 什么是 android.enableD8=false 的替代方案,因为它已被弃用