java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7

How do you run the application? It's probably because you use Gradle as the build system and JDK14 and the Gradle version is old. Reference: https://github.com/gradle/gradle/issues/10248

If you use Gradle Wrapper then refer to $PROJECT_ROOT/gradle/wrapper/gradle-wrapper.properties. The property distributionUrl should be: distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip

If it's an older version then change it, run ./gradlew clean build and try again.


I solved it by editing the gradle-wrapper.properties file inside the gradle folder. (Not .gradle) :

Change this line, from:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip

to:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

rebuild and it's ok.


In the file android/gradle/wrapper/gradle-wrapper.properties, ensure that the distributionUrl is as follows:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip

Note: If you installed jdk 14


Got the same issue on a Maven & SpringBoot project, no Gradle whatever.

The dependency to org.codehaus.groovy is probably transitive through spring-cloud-contract-verifier. Run mvn dependency:tree to view the whole dependency tree.

I got it fixed by upgrading the spring-cloud-contract-maven-plugin version to 2.2.3-RELEASE


Check that your project is running with Java 14 even though it is prepared for Java 8.

My IntelliJ Idea was giving the same error when trying to execute a Gradle task which was running perfectly in command line with JDK 8. The ItelliJ Idea project default JDK was 14 though.