Discussion:
Gradle REPL?
Thibault Kruse
2013-05-04 10:21:36 UTC
Permalink
Hi, this is a response to a 2011 thread I found on nabble while trying to
tackle the same problem.
http://markmail.org/thread/i522eexiq6emad2c

not sure whether this will be placed in the same thread, or how else I
could do so.

Here is my solution, in your build.gradle, do this:

configurations{
addToClassLoader
}

repositories {
mavenCentral()
}

dependencies {
addToClassLoader "jline:jline:1.0"
}
URLClassLoader loader = GroovyObject.class.classLoader
configurations.addToClassLoader.each {File file ->
loader.addURL(file.toURL())
}
task('groovysh') << {
def shell = new org.codehaus.groovy.tools.shell.Groovysh()
shell.interp.context.variables.put("project", this)
shell.run()
}

then run "gradle groovysh -q"

Maybe a gradle plugin writer can package this into a plugin, somehow making
sure the prompt is clean even when not run with "-q".

This gives people new to gradle some useful introspection, like:

groovy:000> project.tasks
===> [task ':assemble', task ':build', task ':buildDependents', task
':buildNeeded', task ':check', task ':classes', task ':clean', task
':compileGroovy', task ':compileJava', task ':compileTestGroovy', task
':compileTestJava', task ':groovydoc', task ':groovysh', task ':jar', task
':javadoc', task ':processResources', task ':processTestResources', task
':test', task ':testClasses']
groovy:000> project.configurations
===> [configuration ':addToClassLoader', configuration ':archives',
configuration ':compile', configuration ':default', configuration
':groovy', configuration ':runtime', configuration ':testCompile',
configuration ':testRuntime']

However it is not all great, since the internal APi is not optimized for
the REPL:
groovy:000> project.dependencies
===>
***@165bece2
groovy:000> project.repositories[0]
===>
***@48c91629

Also groovysh being a bit of a rough diamond still this is not exactly
newbie friendly, but could grow into something great.

Not sure what else this approach could lead to, maybe someone will find
this useful for other things.

Loading...