如何将 `android` Kotlin DSL 添加到 buildSrc 模块中的类路径?

How to add `android` Kotlin DSL to classpath in buildSrc module?

我想在 buildSrc 中制作一些扩展方法,以便在其他模块的 build.gradle.kts-files

中使用它们

特别是我需要扩展 com.android.build.gradle.LibraryExtension。为此,我似乎需要 buildSrc 的类路径中的 com.android.library。试图通过

实现这一目标
plugins {
   id("com.android.library") apply false
}

给我 Plugin [id: 'com.android.library', apply: false] was not found in any of the following sources: 错误。

为此目的的正确设置是什么?

下面 buildSrcbuild.gradle.kts 的完整内容:

buildscript {
   repositories {
      mavenCentral()
      google()
      jcenter()
   }

   dependencies {
      classpath("com.android.tools.build:gradle:3.6.3")
   }
}

plugins {
   `kotlin-dsl`
   id("com.android.library") apply false
}

请忽略我之前发布的所有内容。以下是我如何使用 LibraryExtension。但是,ymmv,这看起来很笨重。

repositories {
    jcenter()
    google()
}

// ...snip...

dependencies {
    implementation("com.android.tools.build:gradle:3.6.3")
}

如果您只想访问 class,您希望它是一个依赖项,而不是一个插件。我仍然不确定如何使它作为 buildSrc 中的插件工作,所以希望这能满足您的需求。