Gradle won't run, java.lang.NoClassDefFoundError: groovy/lang/GroovyObject - groovy

I'm trying to do a basic build with Gradle. Even gradle -v fails with the following:
$ gradle -v
FAILURE: Build aborted because of an internal error.
* What went wrong:
Build aborted because of an unexpected internal error. Please file an issue at: http://www.gradle.org.
* Try:
Run with --debug option to get additional debug info.
* Exception is:
java.lang.NoClassDefFoundError: groovy/lang/GroovySystem
at org.gradle.util.GradleVersion.prettyPrint(GradleVersion.java:183)
at org.gradle.launcher.CommandLineActionFactory$ShowVersionAction.run(CommandLineActionFactory.java:181)
at org.gradle.launcher.CommandLineActionFactory$ActionAdapter.execute(CommandLineActionFactory.java:199)
at org.gradle.launcher.CommandLineActionFactory$ActionAdapter.execute(CommandLineActionFactory.java:191)
(stacktrace snipped)
at org.gradle.launcher.ProcessBootstrap.run(ProcessBootstrap.java:28)
at org.gradle.launcher.GradleMain.main(GradleMain.java:24)
Caused by: java.lang.ClassNotFoundException: groovy.lang.GroovySystem
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 17 more
So, I thought "aha, my classpath is empty. Let me add groovy".
$ export CLASSPATH=/usr/share/gradle/lib/groovy-all.jar && echo $CLASSPATH
/usr/share/gradle/lib/groovy-all.jar
No difference.
For what it's worth, here's the build.gradle:
apply plugin: 'eclipse'
apply plugin: 'groovy'
repositories {
mavenCentral()
}
dependencies {
groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.7.10'
testCompile group: 'junit', name: 'junit', version: '4.8.2'
}
The only relevant stackoverflow question I found was this, and google wasn't much better.
The install doc for gradle says "Gradle ships with its own Groovy library, therefore no Groovy needs to be installed." That implies the classpath would be unnecessary. So why can't I run it?

Sounds like a corrupted Gradle installation. Maybe you aren't calling the gradle script you think you are.

Related

Build Failed with an exception even I changed the gradle to 7.0.3 and also the gradle JDK in Android Studio to version 11

Configure project :app
app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.github.bumptech.glide:compiler:4.12.0'.
FAILURE: Build failed with an exception.
What went wrong:
Task 'package' is ambiguous in root project 'DemoApp'. Candidates are: 'packageDebug', 'packageDebugAndroidTest', 'packageDebugBundle', 'packageDebugUniversalApk', 'packageRelease', 'packageReleaseBundle', 'packageReleaseUniversalApk', 'packageStaging', 'packageStagingBundle', 'packageStagingUniversalApk'.
Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warnings
I had the same error and struggled for a long time to fix it, you have to make some changes in gradle.
First add this to the classpath:
buildscript {
repositories {
...
...
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10'
//add the newest ksp maven version here
classpath "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:1.7.20-Beta-1.0.6"
...
}
}
Be sure that the ksp version match with your kotlin plugin version, you can also check the maven website here: maven
Then in the build.gradle add the ksp plugin, add the new ksp compileOption and change the kap annotatons to ksp:
plugins {
...
...
id 'com.google.devtools.ksp'
}
android{
...
ksp {
arg("room.schemaLocation", "$projectDir/schemas".toString())
}
...
}
dependencies {
...
//room
def roomVersion = "2.4.3"
implementation("androidx.room:room-runtime:$roomVersion")
//replace kap with ksp and should work correctly
ksp "androidx.room:room-compiler:$roomVersion"
implementation("androidx.room:room-ktx:$roomVersion")
...
}

Ionic Android : Error of version conflict of gcm services while adding FCM plugin

Execution failed for task ':processDebugGoogleServices'.
Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0.
In case of Cordova OR Ionic App
I have the similar problem with my ionic 1 cordova build after Integrating the Firebase Cloud Messaging ( FCM )
Error Message
What went wrong:
Execution failed for task ':processDebugGoogleServices'.
Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1.605 secs
Error: /Users/beo-administrator/Documents/projects/Apps/Ionic/psc/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':processDebugGoogleServices'.
Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0.
Solution
I fixed this issue by the following steps
So one fix will be: inside platforms/android open project.properties (Its a file ) , you will have something like this
cordova.system.library.1=com.google.android.gms:play-services-ads:+
cordova.system.library.2=com.google.firebase:firebase-core:+
cordova.system.library.3=com.google.firebase:firebase-messaging:+
Replace the
+
Sign with your target version number - like the following
cordova.system.library.1=com.google.android.gms:play-services-ads:9.0.0
cordova.system.library.2=com.google.firebase:firebase-core:9.0.0
cordova.system.library.3=com.google.firebase:firebase-messaging:9.0.0
Save the file
Then take build using
ionic cordova run android
Go to platforms > android > android build.gradle and add below three lines in dependencies area
compile "com.google.firebase:firebase-core:9.0.0"
compile "com.google.firebase:firebase-messaging:9.0.0"
compile "com.google.android.gms:play-services-gcm:9.0.0"
Now your update dependencies looks like as-
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
// SUB-PROJECT DEPENDENCIES START
debugCompile project(path: 'CordovaLib', configuration: 'debug')
releaseCompile project(path: 'CordovaLib', configuration: 'release')
compile 'com.android.support:support-v4:23.4.0'
compile 'com.facebook.android:facebook-android-sdk:4.14.+'
// compile 'com.google.firebase:firebase-core:+'
// compile 'com.google.firebase:firebase-messaging:+'
// SUB-PROJECT DEPENDENCIES END
compile files('libs/twitter4j-core-4.0.2.jar')
compile 'com.google.code.gson:gson:2.8.0'
compile "com.google.firebase:firebase-core:9.0.0"
compile "com.google.firebase:firebase-messaging:9.0.0"
compile "com.google.android.gms:play-services-gcm:9.0.0"
}
Go to platforms > android > cordova-plugin-fcm. Find file that look like something-FCMPlugin.gradle.
Then change to:
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:+'
classpath 'com.google.gms:google-services:3.0.0' // change this line
}
}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
source:
https://stackoverflow.com/a/44039853/8037833
Had the same problem and the other answers didn't work for me.(as on build the build.gradle get's edited and the version nr return to the previous nr.)
I've fixed it by editing the project.properties file in platforms/android/
target=android-25
android.library.reference.1=CordovaLib
cordova.gradle.include.1=com-sarriaroman-photoviewer/starter-photoviewer.gradle
cordova.system.library.1=com.android.support:support-v4:24.1.1+
cordova.system.library.2=com.android.support:support-v13:25.1.0
cordova.system.library.3=me.leolin:ShortcutBadger:1.1.17#aar
cordova.system.library.4=com.google.firebase:firebase-messaging:11.0.1
cordova.gradle.include.2=phonegap-plugin-push/starter-push.gradle
cordova.system.library.5=com.google.android.gms:play-services-base:11.0.1
cordova.system.library.6=com.google.android.gms:play-services-ads:11.0.1
Make sure that there is the same version of com.google.android.gms

running geb test with gradle 2.3 - HashMap$Entry exception

I am trying to run geb tests through gradle. I've these installed
java version "1.8.0_31"
Groovy Version: 2.4.0
Gradle 2.3
But i am getting this error when running the test.
Exception in thread "main" java.lang.NoClassDefFoundError: java/util/HashMap$Ent
ry
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)
Running a simple groovy script with above setup and the below Build.gradle is fine.
Build.gradle looks like this:
buildscript {
repositories {
jcenter()
}
}
apply plugin: 'java'
apply plugin: 'groovy'
repositories {
jcenter()
mavenCentral()
}
dependencies {
def seleniumVersion = "2.45.0"
def phantomJsVersion = '1.1.0'
// selenium drivers
compile "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
compile "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
compile("com.github.detro.ghostdriver:phantomjsdriver:$phantomJsVersion") {
transitive = false
}
// geb
compile 'org.codehaus.geb:geb-core:0.7.2'
compile 'org.codehaus.geb:geb-spock:0.7.2'
// spock
compile 'org.spockframework:spock-core:0.6-groovy-1.8'
//junit
testCompile group: 'junit', name: 'junit', version: '4.7'
}
task runGebScript (dependsOn: 'classes', type: JavaExec) {
main = 'test'
classpath = sourceSets.main.runtimeClasspath
}
Can someone please help.
According to Gradle dependency report for the build you included, the Groovy version used for testCompile configuration is 1.8.5. Only groovy 2.x is JDK8 compatible. I would do as ataylor suggests and bump Spock version. If you use 1.0-groovy-2.4 then you'll be using Groovy 2.4.1. Also, I would suggest updating version of Geb while you're at it - the latest is 0.10.0. Your dependency versions are way out of date.
Something is trying to use the inner class HashMap.Entry, which no longer exists in Java 8. It's difficult to tell where without a complete stack trace.
However, you're using this version of spock: org.spockframework:spock-core:0.6-groovy-1.8. That version is not compatible with groovy 2.0+. Try updating the dependency to org.spockframework:spock-core:1.0-groovy-2.4.

NoClassDefFound ShortTypeHandling with gradle custom plugin usage

I wrote some groovy code, compiled using compile localGroovy() and published the jar to artifactory.
Now I wrote a gradle plugin, where I have compile localGroovy() and compile "gav of jar above"
I build my plugin and publish to same artifactory.
Now,
To use the above custom plugin, I am having
buildscript {
dependencies {
classpath localGroovy()
classpath "gav of plugin", transitive: true
}
}
As you see, I'm using same localGroovy() everywhere. My gradle version is also same. Now with above, I get the below error:
Caused by: java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/typehandling/ShortTypeHandling
at com.oracle.emdi.tools.lrgmanager.LrgManager.<clinit>(LrgManager.groovy:44)
at com.oracle.emdi.gradle.testinfra.tasks.PrintLrg.class$(PrintLrg.groovy)
at com.oracle.emdi.gradle.testinfra.tasks.PrintLrg.$get$$class$com$oracle$emdi$tools$lrgmanager$LrgManager(PrintLrg.groovy)
at com.oracle.emdi.gradle.testinfra.tasks.PrintLrg.print(PrintLrg.groovy:38)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:219)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:533)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:516)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
As I read in this page and here the issue is related to groovy / gradle version mismatch. But this is not the case here

Gradle Build sample fails with "You must assign a Groovy library to the 'groovy' configuration."

I have a build.gradle file (from the custom plugin example in the manual) that reads:
apply plugin: 'groovy'
dependencies {
compile gradleApi()
compile localGroovy()
}
But when I run I get:
$ gradle build
:compileJava UP-TO-DATE
:compileGroovy
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGroovy'.
> You must assign a Groovy library to the 'groovy' configuration.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Any idea what I am missing?
Ensure you have both:
apply plugin: 'groovy'
and use the groovy keyword in the dependencies section (rather than using the compile keyword):
dependencies {
groovy 'org.codehaus.groovy:groovy-all:2.0.8
}
All credit to this blog.
Short answer, upgrade to a newer version.
The above problem (and a few more) where happening on v1.0.8, upgrading to v1.6 and its all works properly

Resources