NoClassDefFound ShortTypeHandling with gradle custom plugin usage - groovy

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

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

Hilt Unsupported metadata version in Kotlin

I was tried to run my code in Kotlin 1.5.10
With plugin as
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
and dependencies as below
dependencies {
...
//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.33-beta"
kapt "com.google.dagger:hilt-android-compiler:2.33-beta"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0-beta01"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha01'
implementation 'com.android.support:palette-v7:28.0.0'
When I migrate to kotlin_version = "1.5.10", it just errors out stating
error: [Hilt]
Unsupported metadata version. Check that your Kotlin version is >= 1.0: java.lang.IllegalStateException: Unsupported metadata version. Check that your Kotlin version is >= 1.0
at dagger.internal.codegen.kotlin.KotlinMetadata.metadataOf(KotlinMetadata.java:206)
at dagger.internal.codegen.kotlin.KotlinMetadata.from(KotlinMetadata.java:186)
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1133)
...
Can anyone help me? I spent a lot of time on it, your answer will help me a lot
Go to https://dagger.dev/hilt/gradle-setup check Hilt currently version
Update: For now, you can use the newest version.
Kotlin:1.7.0 with Hilt:2.42
Update: kotlin:1.6.0 is compatible with hilt:2.40.5, thanks #Nazanin Nasab
Currently, Kotlin 1.5.21 is compatible with Hilt 2.38.
dependencies {
...
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"
}
I got the same error. I changed two gradle files and It worked for me.
Project Gradle
plugins {
// dependencies for dagger hilt
id 'com.google.dagger.hilt.android' version '2.42' apply false
}
Module Gradle
dependencies {
implementation 'com.google.dagger:hilt-android:2.42'
kapt 'com.google.dagger:hilt-compiler:2.42'
implementation("androidx.hilt:hilt-navigation-fragment:1.0.0")
}
Adding this line to build.gradle dependencies helped me:
kapt("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.3.0")
https://youtrack.jetbrains.com/issue/KT-45885
Thanks for the answer , i had to do a slight tweak in order to work for me because i'm using Arctic Fox, hopefully this answer will help as well
Build.gradle (project)
buildscript {
ext {
compose_version = '1.0.0'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0-alpha05'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.37"
}
}
Build.gradle (app)
//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.34-beta"
kapt "com.google.dagger:hilt-android-compiler:2.34-beta"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha03'
For Kotlin 1.7.10, you just need to make the hilt versions 2.42.
in Project-level build.gradle change hilt version
id 'com.google.dagger.hilt.android' version '2.44' apply false
in App-Level build.gradle
implementation "com.google.dagger:hilt-android:2.44"
kapt "com.google.dagger:hilt-compiler:2.44"
general solution - in AS build console click link at bottom - build with -stacktrace param and find which annotation processor (KAPT) is causing error - then try to update dependency - if you are lucky new version should be available and supporting your gradle version
message in build output you should lookin for
Try:
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.
I got same here. I was using dagger:hilt-android:2.33-beta with Kotlin 1.5.10.Please try this
Project gradle
implementation "com.google.dagger:hilt-android:2.33-beta"
Module gradle
plugins {
...
id 'dagger.hilt.android.plugin'
}
dependencies {
...
//dagger-hilt
implementation "com.google.dagger:hilt-android:2.35.1"
kapt "com.google.dagger:hilt-android-compiler:2.35.1"
}
If any solution solved your problem. Go to https://dagger.dev/hilt/gradle-setup, in Using Hilt with Kotlin section, copy the version mentioned in dependencies and update your build.gradle accordingly
I have an issue when upgrading kotlin-gradle-plugin:1.7.x for fulfill requirement of compose. I revert them to org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21 and kotlinCompilerExtensionVersion value
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
kotlinCompilerExtensionVersion compose_version
in my case, the problem was in the different versions that I specified in the dependencies.
"2.40" in classpath 'com.google.dagger:hilt-android-gradle-plugin'
and
"2.43.2" in implementation 'com.google.dagger:hilt-android'
Firstly check helt dependency versions with below url
https://dagger.dev/hilt/gradle-setup
Check you kotlin versions
Kotlin version 1.6.0
Project level gradle
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.40"
App level gradle
def hilt_version="2.40"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"
Kotlin version 1.7.0
Project level gradle
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"
App level gradle
def hilt_version="2.42"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"

Download and commit gradle dependencies and plugins in Android Studio

This is an excerpt from a build.gradle file for one of my modules. I'm using android-studio-1.5.1 and gradle 2.10.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.google.android.gms:play-services-gcm:9.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
}
I also have classpath 'com.google.gms:google-services:3.0.0' in the project level build.gradle file.
I'm trying to gather all the associated jars into a directory which I can commit to my git repo. Something like:
task copyRuntimeLibs(type: Copy) {
into "${projectDir}/libs"
from configurations.compile
}
(This does not work)
Also, I'm not trying to download the sources or javadocs.
I need to be able to commit all dependencies so that the project can be shared on an intranet without internet access.
I've written a plugin which will download all jars and poms. See the code here to download all jars and all poms from a Gradle Configuration
Note: There's a failing test here which shows that the parent pom's are not being downloaded. I've raised an issue here on Gradle's github.
I will likely improve the plugin to invoke the Maven Model Builder APIs to get the parent poms.
FYI - I've already integrated the ModelBuilder APIs successfully with Gradle (see here and here) so shouldn't be too difficult.

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.

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

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.

Resources