Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which maven dependency to include for evaluating groovy scripts in java application

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?

like image 262
Billybong Avatar asked Jul 12 '13 13:07

Billybong


People also ask

How do I run a Groovy script in Java?

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.

Can you use maven with Groovy?

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.

How do I test my Groovy script?

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.


1 Answers

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>
like image 81
Shawn Guo Avatar answered Oct 21 '22 11:10

Shawn Guo