java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
JavaSpring BootJava Problem Overview
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.
Java Solutions
Solution 1 - Java
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.
Solution 2 - Java
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.
Solution 3 - Java
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
Solution 4 - Java
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
Solution 5 - Java
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.
Solution 6 - Java
in my case, the JRE version used in the Run Configuration was different than the target JDK version in the pom.xml
Solution 7 - Java
I resolve this problem when integrated Facebook 7.19.2 and Google play Games 0.10.09.
In my case JDK and SDK using (and other in Edit/Preferences/External -> Tools-Android
) default paths Unity:
JDK
C:/ProgramFiles/Unity/Hub/Editor/2019.2.12f1/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\OpenJDK\Windows
SDK
C:/Program Files/Unity/Hub/Editor/2019.2.12f1/Editor/Data/PlaybackEngines/AndroidPlayer\SDK
In Environmental Variables(System Proporites/Advanced) added next:
Find(or click new variable under User Variables)
-
JAVA_HOME
and add root JDK path. -
JAVA_BIN
and add path JDK/bin -
JAVA_LIB
and add path JDK/lib
Also, add these paths in System Variables to variable "Path".
Do not use SDK from default Unity and JDK from not Unity default
Then Restart Unity(and better PC).
Then in Editor Unity - Assets/Play -> Service -> Resolve/Android -> Resolver/Force -> Resolve
All Work fine.
Solution 8 - Java
In my case the combination was IntelliJ 2020.2, Kotlin 1.3.72, Maven 3.6.1 and SpringBoot 2.2.1 application. No Gradle used at all in the project.
Somehow IntelliJ had switched to use OpenJDK14 - when reverting back to OpenJDK11 everything started to work again.
Solution 9 - Java
are you using some third party library that brings in org.codehaus.groovy dependencies? If yes, you can try and replace the required groovy dependencies with the most current releases yourself.
In my case it was the org.liquibase:liquibase-groovy-dsl, so I did this:
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-groovy-dsl</artifactId>
<version>2.1.1</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-sql</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-sql</artifactId>
<version>3.0.3</version>
</dependency>
Solution 10 - Java
If you using Android Studio 4.0 or up and having Errors like below
Cause: invalid type code: 17
Cause: invalid type code: fe
Cause: invalid type code: 13
java.lang.NoClassDefFoundError: Could not initialize class
Or
Its says that something wrong with JDK then Follow below steps to resolve the error.
Step 1: First delete .gradle and .idea folder from project directory and restart Android Studio. Make sure it's gone from recycle bin.
Step 2: Go to Project Structure
Step 3: Select SDK Location from the left panel on Project Structure window.
Step 4: Go to JDK Location and click on down arrow then select the jre instead of jdk
C:\Program Files\Android\Android Studio\jre
And it will Solve the errors. Rebuild the project
Note: jre come with the android studio 4 installation not sure about the older version.
This solution work for me.
Solution 11 - Java
I fixed this by adding Apache Groovy 2.4.7 in pom.xml
Solution 12 - Java
in my maven Spring Boot project, I solve the problem by adding dependency:
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>3.0.8</version>
</dependency>
Solution 13 - Java
I solved this by selecting Installed JRE path in window => preferences => java => installed JRE => remve existing & select from local directory.
Make sure you have java_home variable set in environmental variable
Solution 14 - Java
For Maven users, Please follow the below steps to resolve this issue
- You should place rest-assured before the JUnit dependency declaration in your pom.xml / build.gradle in order to make sure that the correct version of Hamcrest is used.
- Add the following dependencies to your pom.xml
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>3.0.8</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>3.0.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-json -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-json</artifactId>
<version>3.0.8</version>
</dependency>
Hope this will fix your issue. It works for me. Instruction mentioned at step#1 copies from Rest Assured official site. Thanks
Solution 15 - Java
Solution 16 - Java
4 things in IntelliJ to check:
- Your Project Structure -> Project -> SDK and Language level
- Settings -> Build,Execution,Deployment -> Build Tools -> Gradle, look at Gradle JVM
- Settings -> Build,Execution,Deployment -> Compiler -> Java Compiler
- Your build.gradle, the Java { sourceCompatibility and targetCompatibility }
Make them all agree on the JDK / language level and it should be fine
Solution 17 - Java
If you are looking for similar solution as @godsim shared, but for gradle liquabase plugin, then modify your configuration section in build.gradle to exclude liquabase's groovy dependency:
configurations {
...
liquibaseRuntime.exclude group: "org.codehaus.groovy"
}
and then manually add groovy in dependencies section:
dependencies {
...
liquibaseRuntime('org.liquibase:liquibase-core:3.8.1')
liquibaseRuntime('org.codehaus.groovy:groovy-all:3.0.3')
liquibaseRuntime 'org.postgresql:postgresql'
liquibaseRuntime('org.liquibase:liquibase-groovy-dsl:2.1.2')
liquibaseRuntime('org.liquibase.ext:liquibase-hibernate5:3.10.2')
liquibaseRuntime('org.springframework.boot:spring-boot-starter-data-jpa')
liquibaseRuntime sourceSets.main.output
...
}
Solution 18 - Java
This issue is solved for me only when I updated compileSdkVersion and targetSdkVersion to 30 with minSdkVersion 19
Solution 19 - Java
Was getting the error when using old versions of spotbugs-maven-plugin
plugin and the corresponding spotbugs
maven dependency.
Fixed by upgrading both to 4.2.0
.
Solution 20 - Java
I have met a similar problem. But my error message is not exactly the same.
I got some ideas from Tarmo and checking the gradle version, eclipse version and the JDK it use.
My error message is:
> Could not open cp_init generic class cache for initialization script 'D:\xxx\TestingEnv\Dev1\eclipse\.metadata\.plugins\org.eclipse.buildship.core\init.d\eclipsePlugin.gradle' (C:\Users\xxx\.gradle\caches\5.6\scripts\6a5krabdzij62jglcll542e66\cp_init\cp_init8a51e2ebf3f7f8302cfbbb80ea3d4b3d).
> Could not initialize class org.codehaus.groovy.classgen.Verifier
I have using SpringToolSuite4 Version: 4.9.0.RELEASE Build Id: 202012132054 for development.
I have 2 projects. Project A and Project B.
Project A, works fine without gradle problem Under this project, gradle> wrapper > gradle-wrapper.propties My distributionUrl is: distributionUrl=https://services.gradle.org/distributions/gradle-4.8-bin.zip
Later, I have another project B and the setting is:
Project B: Under this project, gradle> wrapper > gradle-wrapper.propties My distributionUrl is: distributionUrl=https://services.gradle.org/distributions/gradle-5.6.2-bin.zip
When I select 'refresh gradle' in the IDE, Project B keeps failing build and output the error mentioned above.
I have no clues on it until I found the answer from Tarmo.
Things I have done:
- Try to change the distributionUrl=https://services.gradle.org/distributions/gradle-6.3-bin.zip -The error message changes to other. (Seems we are on the right way)
- Check the JDK version, which Eclipse using to start the itself.
- Under menu bar > Help > About Spring Tool Suite 4 > Installation Details > press 'Configuration Tab > searching for a row start with -vm
- It was originally pointing th OpenJDK, then I changed it to pointing to JDK 1.8 at my local machine. It failed to start since it is not supported the older version of JDK.
- I downloaded the older version of STS sts-4.4.1.RELEASE
- Now, I import the project again, press 'refresh gradle', it works fine and the gradle task shows properly in the IDE.
- In the sts-4.4.1.RELEASE folder, adding an entry into SpringToolSuite4.ini to pointing to use JDK 1.8 at my local PC.
C:/Program Files/Java/jdk1.8.0_301/bin/javaw.exe
-If not specify, it would use the openjdk to start with by default. It is a good practice to specify the version we use.
Appendix SpringToolSuite4.ini https://wiki.eclipse.org/Eclipse.ini
Solution 21 - Java
If you are on Windows operating system and using Android Studio, you should run Android Studio as Administrator.
Solution 22 - Java
Move to JDK 11, it should work.