我试图了解如何从项目属性中设置插件约定属性。
这是 gradle 发行版中的 customPluginWithConvention 示例 (gradle-0.9.2\samples\userguide\organizeBuildLogic\customPluginWithConvention\build.gradle)
apply plugin: GreetingPlugin
greeting = 'Hi from Gradle'
class GreetingPlugin implements Plugin<Project> {
def void apply(Project project) {
project.convention.plugins.greet = new GreetingPluginConvention()
project.task('hello') << {
println project.convention.plugins.greet.greeting
}
}
}
class GreetingPluginConvention {
def String greeting = 'Hello from GreetingPlugin'
}
在没有项目属性的情况下运行此脚本:
>gradle hello
:hello
Hi from Gradle
BUILD SUCCESSFUL
现在尝试通过设置项目属性来设置自定义消息:
>gradle -Pgreeting=goodbye hello
:hello
Hello from GreetingPlugin
显示的是约定的默认问候语,而不是预期的“再见”。是否可以覆盖消息?