I'm running an external groovy script via gmaven plugin in pom.xml. The external script is say 'myscript.groovy'.
I want to provide some parameters/arguments to myscript.groovy via the maven pom.xml [i.e. inside the plugin 'gmaven-plugin' execution]; but unable to do so..
I've tried using in ; but not sure how to retrieve its values in the groovy script. Simply calling properties.get is not giving the property value.
Snap of pom file:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>generate-resources-execute-groovyscript</id>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<properties>
<property>
<name>installation.dir</name>
<value>${installation.dir}</value>
</property>
</properties>
<source>${pom.basedir}/src/main/groovy/configure.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
Not sure how to retrieve the value of 'installation.dir' property in 'configure.groovy' script.
Any hint in this regard will be useful.. thanks
There are two ways you can bind and retrieve properties. One would be through plugin-specific properties.
These would be retrieved in the script like
project.properties['installation.dir']
.GMaven isn't maintained anymore (I was the last maintainer). If you want to use versions of Groovy newer than 2.0.0, have a look at GMavenPlus. Here's the equivalent POM:
Retrieval in this case would be like
properties['installation.dir']
. I know thefile:///
is annoying. I've removed the requirement for that in the next release.For GMaven or GMavenPlus, if you choose the plugin properties approach, you will need to set the value elsewhere either with something like this in your project POM
Or include it in your call like
mvn -Dinstallation.dir=C:\someDir
The other option is to bind to project level properties directly. You would put it in your project level properties or in your call, like mentioned above, and don't include
<properties>
in the plugin<configuration>
. If you go this route, you'd access in your script byproject.properties['installation.dir']
for either GMaven or GMavenPlus (also take out<bindPropertiesToSeparateVariables>
for GMavenPlus in this case).If this doesn't work for you, try renaming
installation.dir
to something likeinstallationDir
. I can't remember offhand if periods were problematic.