【发布时间】:2016-10-26 12:51:52
【问题描述】:
我正在关注 Gradle 文档的 Writing Custom Plugins 部分,特别是关于 Getting input from the build 的部分。文档提供的以下示例完全符合预期:
apply plugin: GreetingPlugin
greeting.message = 'Hi from Gradle'
class GreetingPlugin implements Plugin<Project> {
void apply(Project project) {
// Add the 'greeting' extension object
project.extensions.create("greeting", GreetingPluginExtension)
// Add a task that uses the configuration
project.task('hello') << {
println project.greeting.message
}
}
}
class GreetingPluginExtension {
def String message = 'Hello from GreetingPlugin'
}
输出:
> gradle -q hello
Hi from Gradle
我想让自定义插件执行一个外部命令(使用Exec task),但是当将任务更改为一个类型(包括 Exec 以外的类型,例如Copy)时,构建的输入停止正常工作:
// previous and following sections omitted for brevity
project.task('hello', type: Exec) {
println project.greeting.message
}
输出:
> gradle -q hello
Hello from GreetingPlugin
有人知道问题出在哪里吗?
【问题讨论】:
标签: gradle gradle-plugin