使用项目属性覆盖插件约定属性
我试图了解如何从项目属性设置插件约定属性。
这是来自 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
显示约定的默认问候语,而不是预期的“再见”。是否可以覆盖该消息?
I am trying to understand how to set a plugin convention property from a project property.
Here is the customPluginWithConvention example from the gradle distribution (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'
}
Running this script with no project property:
>gradle hello
:hello
Hi from Gradle
BUILD SUCCESSFUL
And now trying to set a custom message via setting a project property:
>gradle -Pgreeting=goodbye hello
:hello
Hello from GreetingPlugin
Instead of the expected "goodbye" the default greeting of the convention is shown. Is it possible to override the message?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前还没有,但我们应该努力使其成为可能。请在 http://jira.codehaus.org/browse/GRADLE 创建问题。
Not yet, but we should try to make it possible. Please create an issue at http://jira.codehaus.org/browse/GRADLE.