2

我试图了解如何从项目属性中设置插件约定属性。

这是 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

显示的是约定的默认问候语,而不是预期的“再见”。是否可以覆盖消息?

4

1 回答 1

0

是否可以覆盖消息?

还没有,但我们应该努力让它成为可能。请在http://jira.codehaus.org/browse/GRADLE创建问题。

于 2011-02-03T06:15:27.667 回答