Hello Sean,

On 25/04/05, M. Sean Gilligan <[EMAIL PROTECTED]> wrote:
> [snip]
> My first choice would be Groovy (or perhaps Beanshell) as I don't want to 
> learn Python, and am not sure JavaScript gives me the file access that I 
> need.  (I know Groovy has its warts, but it works fairly well for me in short 
> scripts.)
> [snip]

I managed to use Groovy scripts inside Maven with the Groovy Ant task
which will be shipping in the next version of Groovy (it's currently
in CVS head only).

So if you want to use some Groovy code in your build, you'll have to
build Groovy from sources, or wait for a few weeks the next release
(jsr-02).

I've had hard times trying to find a solution to acces the POM and
other objects, but I've managed to find a very ugly workaround to make
that possible:

<?xml version="1.0" encoding="UTF-8"?>
<project default="groovy" xmlns:ant="jelly:ant"> 
  <goal name="groovy">
    <ant:taskdef name="groovy"
classname="org.codehaus.groovy.ant.Groovy"
classpathref="maven.dependency.classpath"/>
    <ant:groovy>
        def contextField = 
project.propsHandler.class.getDeclaredField("context")
        contextField.setAccessible(true)
        def context = contextField.get(project.propsHandler)
        println context.project.class
    </ant:groovy>
  </goal>
</project>

Unfortunately, the GrantProject instance (here the variable project)
has got a context which is private, and that I could only access
through the setAccessible(true) magic. What a pain...
I wonder why there's no getter on the context! That would be so much better!

In my project.xml, I've added the dependency on groovy-all-xxxx.jar
which I've added manually to my local repository (since the next
version of Groovy is not yet out in the wild) :

    <dependency>
      <groupId>groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <version>1.0-jsr-02-SNAPSHOT</version>
      <properties>
        <classloader>root</classloader>
      </properties>
    </dependency>

And after that... that works.

We could probably write a small Groovy Maven plugin for that, to
simplify the dirty stuffs.

Question to Maven developers:

Why can't we access the context within the propsHandler of
GrantProject? That would simplify the job :-)

-- 
Guillaume Laforge
http://glaforge.free.fr/weblog/?catid=2

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to