Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am getting this exception java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7 and java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache) when i run the spring boot application

I am using below tools

STS 3.9.10 release
Open JDK 14 64 bit
Spring boot 2.2.5

It worked fine with oracle jdk but its failing to run with openjdk. I am not using any groovy libs. This is maven based spring boot project.

like image 646
user3365200 Avatar asked Sep 26 '22 10:09

user3365200


4 Answers

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.

like image 164
Tarmo Avatar answered Oct 19 '22 20:10

Tarmo


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.

like image 58
Mohammed alsheikh Avatar answered Oct 19 '22 19:10

Mohammed alsheikh


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

like image 52
arslan Avatar answered Oct 19 '22 21:10

arslan


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

like image 14
BertKoor Avatar answered Oct 19 '22 19:10

BertKoor