GMaven Problems, back to maven-antrun-plugin

I use gmaven to run groovy scripts in several of my builds. In the last few weeks I started to have problems. The errors were cryptic and taking far too long to track down. Since nothing had changed in my project config, I decided to fall back to using ant to run the scripts.

So, in the interest of moving forward, I switched back to using maven-antrun-plugin. I had moved away from this because it was difficult to find information about accessing project information from within the script. For instance, I have some code generators. I need the script to know the source dir. Until now, I was not able to find out how to access that contextual information from within the script. It turns out, that there is a “binding” variable(type groovy.lang.Binding) automatically set on your object. Here is a print of the data that was in the binding variable for this particular project:

["project":org.apache.tools.ant.Project@b63a69, "args":[], "task":org.codehaus.groovy.ant.Groovy@1b4f82d, "target":, "properties":["ant.project.name":"DummyProject", "basedir":"/home/username/development/code/blah/beip/trunk/gap/framework"], "ant":groovy.util.AntBuilder@11761b]

So, you can get the basedir within your script as follows:

this.binding.getVariable('properties')['basedir']

Here is the plugin config for reference:

<plugin>
    <artifactid>maven-antrun-plugin</artifactid>
    <executions>
            <execution>
                    <id>compile</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="maven.runtime.classpath"></taskdef>
                            <groovy src="${basedir}/src/main/script/compressJs.groovy" classpathref="maven.runtime.classpath"/>
                        </tasks>
                    </configuration>
                </execution>
        </executions>
</plugin>
Related Posts with Thumbnails
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • DZone
  • Facebook
  • Furl
  • Google Bookmarks
  • YahooBuzz
  • YahooMyWeb

About this entry