我试图了解如何从项目属性设置插件约定属性。
以下是gradle发行版中的customPluginWithConvention示例(gradle-0.9.2 \ samples \ userguide \ organizationalBuildLogic \ 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
显示约定的默认问候语,而不是预期的“再见”。是否可以覆盖该消息?