Alex Rivera | Logout

Run groovy script from within gradle

Asked 2010-03-02T02:18:36.080
19

What's the best way to create a gradle task, which runs a groovy script? I realize that gradle build files are groovy, so I would think it would be possible to do something like this:

task run << {
    Script app = new GroovyShell().parse(new File("examples/foo.groovy"))
    // or replace .parse() w/ a .evalulate()?
    app.run()
}

I get all kinds of whacky errors when I try this if bar.groovy is using @Grab annotations or even doing simple imports. I want to create a gradle task to handle this, so that I can hopefully reuse the classpath definition.

Would it be better to move the examples directory into the src directory somewhere? What's a best practice?

Edit
Report

1 Answer

2

http://wayback.archive.org/web/20131006153845/http://docs.codehaus.org/display/GRADLE/Cookbook#Cookbook-runningthingsfromGradle

ant.java(classname: 'com.my.classname', fork: true,
         classpath: "${sourceSets.main.runtimeClasspath.asPath}")
answered 2011-01-12T08:32:32.927

Your Answer