8

I need to see my dependencies in Gradle to fix a problem with multiple SLF4J bindings.
However, when I run 'gradle dependencies' I get the error:

Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

In a similar question in stack-overflow Android Studio Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
it was recommended to

  1. install java jdk-14
  2. upgrade to gradle version 6.3

I changed the jdk to 14 in IntelliJ in 2 places:

  1. File -> Project Structure -> Project -> Project SDK
  2. Preferences -> Gradle -> Gradle JVM

I attempted to update gradle from the command line with: 'gradle wrapper --gradle-version 6.3' and got the same error:

Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

I then changed the field 'distributionUrl' in the file 'gradle-wrapper.properties' to 'gradle-6.3', as instructed here https://github.com/gradle/gradle/issues/10248.

I tried various combinations of jdk and gradle versions but nothing seems to work.

Bashir
  • 2,057
  • 5
  • 19
  • 44
Joshua Spinak
  • 133
  • 1
  • 1
  • 10

3 Answers3

5

So from your repo, if you have gradle-wrapper.properties like this:

➜ cat gradle/wrapper/gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

On first compilation, Gradle tells you that:

  build file '/Users/tim/Code/Java/brobotREST/build.gradle': 36:
     all buildscript {} blocks must appear before any plugins {} blocks in the script

So if you move the buildscript section up to the top of the build.gradle file, it all seems to work

And I get:

➜ ./gradlew -version

------------------------------------------------------------
Gradle 6.3
------------------------------------------------------------

Build time:   2020-03-24 19:52:07 UTC
Revision:     bacd40b727b0130eeac8855ae3f9fd9a0b207c60

Kotlin:       1.3.70
Groovy:       2.5.10
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          14 (Azul Systems, Inc. 14+36)
OS:           Mac OS X 10.15.4 x86_64
tim_yates
  • 167,322
  • 27
  • 342
  • 338
  • Thank you Tim for helping me out, I really appreciate it :) I made the changes but nothing changed. What's also strange is that I never got the `buildscript` error message that you did. The program always compiled successfully for me, even with `buildscript` at the bottom of the build.gradle file. It gives a couple warnings: `annotationProcessor intersects with a source root`, but compiles. As you instructed, I... – Joshua Spinak Apr 21 '20 at 20:26
  • ... put the `buildscript` section at the top and tried to run `./gradlew -version` again, but with the same results. The build also compiles and gives the same output. I then deleted the whole `buildscript` section (I hadn't set up the local repository yet anyway). Same results :/ – Joshua Spinak Apr 21 '20 at 20:26
  • @JoshuaSpinak I sent a PR to your project to add the wrapper properties and jar to the repo... That's working on my machine... Check you're running `./gradlew tasks` or `./gradlew -version` – tim_yates Apr 21 '20 at 21:09
2

I had a similar problem on macOS. It seems, it was a problem with version difference by IntelliJ IDEA and Gradle. I adjusted the Gradle version in /gradle/gradle-wrapper.properties. In my case I have set: distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip

and now it works. See also Gradle: Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

zr0gravity7
  • 2,917
  • 1
  • 12
  • 33
Viktor Sirotin
  • 169
  • 1
  • 8
1

Had a similar problem on Windows 10 caused by a java version issue. In build.gradle set the java source compatibility flag; For java 1.8 this is

sourceCompatibility = '1.8'

then check the system version is the same

java -version

Stephen L.
  • 64
  • 3