user3365200
user3365200

Reputation: 2231

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.

Upvotes: 207

Views: 404840

Answers (25)

Mohammed alsheikh
Mohammed alsheikh

Reputation: 887

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.

Upvotes: 70

Jonny S.
Jonny S.

Reputation: 1

Typically when i run into this error i am trying to open an older project. A fix for me is going into the Android Studio settings and downgrading the gradle settings to match the build.

Upvotes: 0

RenatoIvancic
RenatoIvancic

Reputation: 2092

I had to work on a project with Gradle version 6.0.1. First I wanted to update the Gradle wrapper while then later I got other issues. So to stay with Gradle wrapper 6.0.1, I had to downgrade Java version from 17 to 8.

In Eclipse I had to override workspace settings in the Advanced section with setting explicitly Java home. Otherwise the project wouldn't load at all.

enter image description here

In IntelliJ IDEA the case was that project could open while it presented following error.

enter image description here

Again I had to downgrade Java version to 8 from 17 in the Gradle build window: enter image description here

For a long shot it definitely makes sense to upgrade the project.

Upvotes: 0

ddc
ddc

Reputation: 96

It can also happen because you forgot to indicate your Android SDK via local.properties in a freshly cloned Android Project.

Upvotes: 0

Ankush
Ankush

Reputation: 519

It was coming for me in Idea, and got resolved after setting JAVA_HOME in .zshrc and .bash_profile, source both the files and restart the Idea.

export JAVA_HOME="<Path to JDK just above bin " # For e.g it was "/opt/homebrew/opt/openjdk@11" in my Mac machine could be /Contents/Home based on you have used homebrew or manually gunzipped

Upvotes: 1

jkwli
jkwli

Reputation: 51

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:

  1. 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)
  2. 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.
  1. 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.
  1. 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

Upvotes: -1

bigwig87
bigwig87

Reputation: 101

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

Upvotes: 4

Tarmo
Tarmo

Reputation: 4081

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.

Upvotes: 195

imad bouhafer
imad bouhafer

Reputation: 11

I simply changed the gradle version for the project to the newer version.

a screenshot of the upgrade

PS. I use kotlin

Upvotes: 1

Yu Jiaao
Yu Jiaao

Reputation: 4714

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>

Upvotes: 12

Anas Naguib
Anas Naguib

Reputation: 1116

If you are on Windows operating system and using Android Studio, you should run Android Studio as Administrator.

Upvotes: -3

azeem bhopal
azeem bhopal

Reputation: 59

For Maven users, Please follow the below steps to resolve this issue

  1. 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.
  2. 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

Upvotes: 2

Nilesh Suryawanshi
Nilesh Suryawanshi

Reputation: 119

I fixed this by adding Apache Groovy 2.4.7 in pom.xml

Upvotes: 3

Alled Luviette
Alled Luviette

Reputation: 71

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.

Upvotes: 0

Gulshan Yadav
Gulshan Yadav

Reputation: 451

This issue is solved for me only when I updated compileSdkVersion and targetSdkVersion to 30 with minSdkVersion 19

Upvotes: 0

Jan Cizmar
Jan Cizmar

Reputation: 365

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
    ...
}

Upvotes: 0

Sandip Jadhav
Sandip Jadhav

Reputation: 173

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

Upvotes: 1

Jeeka
Jeeka

Reputation: 881

in my case, the JRE version used in the Run Configuration was different than the target JDK version in the pom.xml

SpringBoot_Run_Config

Upvotes: 7

arslan
arslan

Reputation: 1144

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

Upvotes: 52

Erik Finnman
Erik Finnman

Reputation: 1667

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.

Upvotes: 4

user8116670
user8116670

Reputation: 1

Move to JDK 11, it should work.

Upvotes: -8

BertKoor
BertKoor

Reputation: 201

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

Upvotes: 16

Kiryha
Kiryha

Reputation: 41

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.

Upvotes: 4

Sergey Shcherbakov
Sergey Shcherbakov

Reputation: 4778

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.

Upvotes: 8

godsim
godsim

Reputation: 311

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>

Upvotes: 4

Related Questions