Why am I getting a NoClassDefFoundError error when trying to compile using the new Groovy 3.0.4 compiler? - groovy

I am trying to compile a project using the new Groovy 3.0.4 compiler and Gradle 5.6.4:
dependencies {
implementation "org.codehaus.groovy:groovy-all:3.0.4"
...
But the compilation (./gradlew --stacktrace build) fails with the error:
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileGroovy'.
...
Caused by: java.lang.NoClassDefFoundError: org/codehaus/groovy/transform/stc/AbstractExtensionMethodCache
...
The class AbstractExtensionMethodCache is part of the Groovy compiler, why the compiler cannot find it? The project compiles fine with Groovy 2.5.12.

Related

Cant run an Android Studio project with Apache POI libraries

For the second time I decided to give a try to Android Studio.
So I imported a project that uses Apache POI libraries, and others.
This is my dependencies:
compile 'com.google.http-client:google-http-client-gson:1.19.0'
compile 'com.google.code.gson:gson:2.1'
compile 'com.android.support:appcompat-v7:19.1.0'
compile 'com.google.android.gms:play-services:+'
compile files('libs/commons-codec-1.9.jar')
compile files('libs/commons-logging-1.1.3.jar')
compile files('libs/google-api-client-1.16.0-rc.jar')
compile files('libs/google-api-client-android-1.16.0-rc.jar')
compile files('libs/google-api-services-drive-v2-rev111-1.16.0-rc.jar')
compile files('libs/google-http-client-1.16.0-rc.jar')
compile files('libs/google-http-client-android-1.16.0-rc.jar')
compile files('libs/google-http-client-jackson-1.16.0-rc.jar')
compile files('libs/google-http-client-jackson2-1.16.0-rc.jar')
compile files('libs/google-oauth-client-1.16.0-rc.jar')
compile files('libs/jackson-core-2.1.3.jar')
compile files('libs/jsr305-1.3.9.jar')
compile files('libs/log4j-1.2.17.jar')
compile files('libs/poi-3.11-20141221.jar')
When I try to run, I have this error:
04:27:59.765 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
04:27:59.766 [ERROR] [org.gradle.BuildExceptionReporter]
04:27:59.767 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
04:27:59.768 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':app:dexDebug'.
04:27:59.769 [ERROR] [org.gradle.BuildExceptionReporter] > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_75\bin\java.exe'' finished with non-zero exit value 2
When compiling with --stacktrace --info --debug, I get this:
04:27:59.754 [ERROR] [org.gradle.api.Project] AGPBI: {"kind":"SIMPLE","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","position":{},"original":"UNEXPECTED TOP-LEVEL EXCEPTION:"}
AGPBI: {"kind":"SIMPLE","text":"com.android.dex.DexException: Multiple dex files define Lcom/google/api/client/util/StreamingContent;","position":{},"original":"com.android.dex.DexException: Multiple dex files define Lcom/google/api/client/util/StreamingContent;"}
I noticed that when I remove the poi-3.11-20141221.jar everything works fine.
I searched for a long time this issue but I'm starting to get sick of it and considering seriously to return to eclipse for good.
So my question is:
What I am suppose to do to get my project works in Android Studio with POI libaries?
Thank you
I get it!!!
I realize the problem was using Apache POI, google drive and Google Play service libraries in the same project. All these libs introduce too many methods in my project.
To avoid the compile error, I just enable the multiDex in the build gradle:
defaultConfig {
multiDexEnabled = true
}
And it works! So happy now :)
I found this solution here:
Unable to execute dex: method ID not in [0, 0xffff]: 65536

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

Geb + Spock + groovy setup

So I've been attempting to get these tools running together, but I can't seem to get things setup properly. Each time I am presented with the following error:
The project was not built since its build path is incomplete. Cannot find the class file for org.spockframework.mock.MockController. Fix the build path then try building this project.
I've created this gist. When I run gradle chrome test I get the following output:
gradle chrome test
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:compileTestGroovy FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestGroovy'.
> org/spockframework/mock/MockController
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
I'm using gradle 1.3, geb 0.7.2 and spock 0.7-groovy-2.0. I've also tried updating geb to utilize 0.9.0-RC-1. The gist above should have everything needed to see this same error.
This is what you get when you run Spock 0.7 with Geb versions lower than 0.9.0-RC-1 (which aren't compatible with Spock 0.7). Double check your setup and perform a clean build.
I was running into the same problem. It turns out you need to use the groovy 1.8 version because the Geb/Spock integration jars haven't been upgraded to groovy 2.0 yet. The following setup worked for me:
dependencies {
def seleniumVersion = "2.42.2"
def phantomJsVersion = '1.1.0'
def cargoVersion = '1.4.9'
// selenium drivers
compile "org.seleniumhq.selenium:selenium-ie-driver:$seleniumVersion"
compile "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
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'
compile 'junit:junit:4.8.2'
compile 'org.slf4j:slf4j-log4j12:1.7.6#jar'
compile 'org.slf4j:slf4j-api:1.7.6#jar'
}
I posted my full script that includes cargo integration on my blog: http://www.openscope.net/2015/02/21/how-to-configure-gebspock-with-gradle/

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