I have a groovy script like so:
@Grab('com.univocity:univocity-parsers:2.0.0')
import com.univocity.parsers.csv.*;
class MyCsvParser {
}
And I want to load this class in my java application via GroovyClassLoader. But the @Grab somehow yields in an ivy exception:
SomeJavaClass {
    void someMethod() {
         String script = FileUtils.readFileToString("the groovy File");
         Class c = new GroovyClassLoader(this.getClass().getClassLoader())).parse(script);
    }
}
Stack:
Caused by: java.lang.ClassNotFoundException: org.apache.ivy.core.report.ResolveReport
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 41 more
When I comment out the @Grab everything works just fine. How can I enable the Grapes in GroovyClassLoader?
You should add the ivy dependency. It's not added by default because it's declared as non-transitive. Ivy is the library which manages the dependencies loaded by @Grab:
<dependency>
  <groupId>org.apache.ivy</groupId>
  <artifactId>ivy</artifactId>
  <version>2.4.0</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