Class getting not found: org.apache.ivy.core.report.ResolveReport when using GroovyClassLoader in Java

I have a groovy script like this:

@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 @Grab is somehow inferior in ivy exclusion:

 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 on @Grab everything works fine. How to enable Grapes in GroovyClassLoader ?

+5
source share
1 answer

You must add ivy addiction. It is not added by default because it is declared as non-transitive. Ivy is a library that manages the dependencies downloaded by @Grab :

 <dependency> <groupId>org.apache.ivy</groupId> <artifactId>ivy</artifactId> <version>2.4.0</version> </dependency> 
+10
source

Source: https://habr.com/ru/post/1244531/


All Articles