开发者

How do you pass args to gmaven groovy:execute?

I need to pass in some args to a groovy script that is executed via the gmaven. I can do this no problem if I execute the script directly on the command line like so:

printArgs.groovy...

for (a in this.args) {
  println("Argument: " + a)
}

command...

$groovy printArgs.groovy fe fi fo fum 

output...

Argument: fee
Argument: fi
Argument: fo
Argument: fum

I can't see how to pass these args in to via the plugin though using mvn groovy:execute. Ideally, I want to set some default params in the 开发者_开发知识库plugin config, but be able to override them when i execute the command. It would be nice to be able to pass them as named-args too if possible.

<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.3</version>
    <configuration>
        <source>${pom.basedir}/src/main/resources/printArgs.groovy</source>
    </configuration>
</plugin>

The plugin documentation is a bit scarce (and also outdated). I see there is a 'properties' optional param but I don't think this is to be used for this purpose (or if it is, i can't get it to work!).

Cheers :)


Ok, I can answer my own question for reference sake...

Rather than pass in a list of args, it is possible to reference the project properties very simply as follows:

def someProp = project.properties['someProp']

In doing this, you can reference any properties defined in a tag within the pom. Furthermore, you can define the properties in the same configuration tag as the groovy script.

Gmaven plugin config...

<configuration>
    <properties>
        <name>world</name>
    </properties>
    <source>${pom.basedir}/src/main/resources/bootstrap/helloWorld.groovy</source>
</configuration>

HelloWorld.groovy...

println("Hello $project.properties.name!")
// this also works
// println("Hello $project.properties['name']!")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜