1

Using @grab for the first time (new to groovy)

I understand it is meant to work "out the box."

However, when I add this to my class:

@Grab(group='commons-lang', module='commons-lang', version='2.4')

I get the following compilation error:

Caused by: java.lang.NoClassDefFoundError: org/apache/ivy/plugins/resolver/DependencyResolver

Groovy version is Groovy Version: 3.0.4 JVM: 11.0.1 Vendor: Oracle Corporation OS: Mac OS X

Jake
  • 4,322
  • 6
  • 39
  • 83
  • 1
    how do you start groovy? – daggett Jun 17 '20 at 23:09
  • through an intellij unittest. But compiling through gradle throws a compilation error too, also referring to DepenencyResolveer – Jake Jun 18 '20 at 00:08
  • 3
    then you have missing dependency to ivy-2.4.0.jar – daggett Jun 18 '20 at 02:43
  • 2
    you could setup dependency to [groovy-all](https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all/3.0.4). it includes all other libraries – daggett Jun 18 '20 at 02:50
  • solved it! the weird thing is I had tried putting ivy in the build.gradle both as buildSrc and regular dependencies – Jake Jun 18 '20 at 07:52
  • 1
    Please make your two comments into an answer. This problem is mentioned all over the internet but no definitive answer – Jake Jun 18 '20 at 07:53

2 Answers2

2

you have missing dependency or library ivy-2.4.0.jar

this library is a part of groovy-all artifact. check groovy-all.pom to see all groovy dependencies/features

so, you could setup dependency to groovy-all artifact in your project

or to a separate ivy-2.4.0.jar artifact if you don't want to include all groovy features into your project

daggett
  • 26,404
  • 3
  • 40
  • 56
2

Try adding this to gradle.build

configurations {
  ivy
}

dependencies {
  ivy "org.apache.ivy:ivy:2.4.0"
 ...
}

tasks.withType(GroovyCompile) {
  groovyClasspath += configurations.ivy
}

Max Prokopov
  • 1,308
  • 11
  • 16