I've added the ability to parse and evaluate groovy scripts inside my java application using GroovyShell. Which maven artifact is the bare minimum to include in my build?
I know that the groovy-all will definitely contain everything I need, but I'm guessing that there is a smaller package I could use as well?
With the GroovyClassLoader we can load Groovy scripts and run them in Java code. First we must create a new GroovyClassLoader and then parse a Groovy script. The script can be in a file, string or inputstream. Once the script is parsed we have a Class and we can make a new instance of this class.
The execution of the Groovy script can be bound to any Maven phase; furthermore, inside the script, the objects session and project can be used to interact with the Maven build.
You can test Groovy applications using JUnit 4 and JUnit 5 testing frameworks. Open a class in the editor, for which you want to create a test and place the cursor within the line containing the class declaration. Press Ctrl+Shift+T and select Create New Test.
groovy-jsr223 is the JSR-223 Engine implementation, and it support evaluation of groovy scripts via JSR-223 standard interface.
ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("groovy");
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-jsr223</artifactId>
<version>2.4.6</version>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With