Search code examples
groovycompilationclassloader

How to force Groovy Script Engine to output compiled classes in files?


I googled and found out you can make GroovyScriptEngine output scriptCache into class files by setting setTargetDirectory. But when I execute the code something like below from scala, it doesn't generate class files.

How do you set GroovyScriptEngine to output class files from scripts compiled by GroovyScriptEngine?

var gse = new GroovyScriptEngine()
gse.getConfig().setTargetDirectory("c:/test")
var scriptClass = gse.loadScriptByName("SomeGroovyClass.groovy")

Solution

  • The GroovyScriptEngine does not seem (from looking at the source) to use that property of CompilerConfiguration

    It would need to be passed in the constructor of the inner ScriptClassLoader, so that the GroovyClassLoader that it extends gets the configuration when it is constructed.