On 05/08/2011, at 3:18 AM, Kenneth Kousen wrote: > Hi Peter, > > Thanks for the help, but I still don't quite have it. Here's the idea: I have > a web application whose data resides in a database. I have a script that > generates that database, which uses some of the classes in my domain. > > What I want to do is to execute that script as part of the build process, but > only if the database doesn't already exist (for testing I'm using H2 and > storing the database in the build directory). I think I can do that using the > inputs/outputs properties of a task. The only problem I'm having is executing > the script itself. > > I tried adding configurations.runtime.asPath, but that included only the > dependent jars and not my compiled classes.
You want sourceSets.main.runtimeClasspath.asPath, instead. > > More below: > > On Thu, Aug 4, 2011 at 10:51 AM, Peter Niederwieser <[email protected]> > wrote: > > Kenneth Kousen wrote: > > > > I tried using a CompilerConfiguration: > > > > def config = new > > org.codehaus.groovy.control.CompilerConfiguration(classpath:sourceSets.main.runtimeClasspath) > > new GroovyShell(new Binding(), config).evaluate(script) > > > > but again the classes in the script aren't found. > > > > sourceSets.main.runtimeClasspath is a FileCollection, but > CompilerConfiguration.setClasspath() expects a String. > > Try this: new CompilerConfiguration(classpath: > configurations.runtime.asPath) > > As I say, that includes the runtime jars, but not my compiled classes. > > Even better, introduce your own configuration (e.g. 'script') and use that. > > Um, how do I do that? Can you point me to an example? > > > Kenneth Kousen wrote: > > > > I know there's a JavaExec task, but I don't see a GroovyExec task and it > > seems a > > bit strange to artificially wrap my script in a Java program just to run > > this. > > > > Compiled Groovy scripts can be run with JavaExec as-is. Might make sense to > have something for source scripts, although inlining and "apply from:" are > also options. > > If I understand the JavaExec tasks, I need to know the compiled class name. > What's that for a script? (I might be able to figure that one out. :) > > Again, thanks for your help, > > Ken > > -- > Peter Niederwieser > Principal Engineer, Gradleware > http://gradleware.com > Creator, Spock Framework > http://spockframework.org > Blog: http://pniederw.wordpress.com > Twitter: @pniederw > > > -- > View this message in context: > http://gradle.1045684.n5.nabble.com/Run-groovy-script-from-gradle-with-classpath-tp4664822p4666604.html > Sent from the gradle-user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > > > > -- > Kenneth A. Kousen > President > Kousen IT, Inc. > -- Adam Murdoch Gradle Co-founder http://www.gradle.org VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting http://www.gradleware.com
