我正在编写一个 Gradle 插件,但无法让 apply plugin:
命令在使用该插件的 Gradle 脚本中工作。我正在使用 Gradle 1.1。
我已经用 clean build
构建了插件,我现在正尝试通过一个平面 repo 将它添加到 Gradle 构建中。这似乎有效,但 Gradle 没有发现有一个 ID 为 test-plugin
的插件。插件的 settings.gradle
中的项目名称是 test-plugin
并且 META-INF/gradle-plugins
中的属性文件也是 test-plugin.properties
。我不确定在哪里可以指定插件 ID。
项目中使用test-plugin
的build.gradle
文件:
repositories {
flatDir name: 'libs', dirs: "../build/libs"
}
dependencies {
compile 'test:test-plugin:0.1'
}
apply plugin: 'test-plugin'
来自 Gradle 的错误:
What went wrong:
A problem occurred evaluating root project 'tmp'.
Plugin with id 'test-plugin' not found.
最佳答案
插件 Jar 必须添加为 构建脚本依赖项:
buildscript {
repositories { flatDir name: 'libs', dirs: "../build/libs" }
dependencies { classpath 'test:test-plugin:0.1' }
}
apply plugin: "test-plugin"
关于plugins - 未找到自定义 Gradle 插件 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12569916/