What to do when Gradle raises unexpected NoClassDefFoundException

2011-10-26  |   |  groovy   java   tool  

I have just lost an hour thanks to some obscure bug in Gradle caching mechanism.

If all of the sudden, Gradle raises Frankenstein errors at you like

$ gradle clean build

:buildSrc:compileJava UP-TO-DATE

:buildSrc:compileGroovy

Note: /Users/manu/projects/notbackedup/git/core/buildSrc/src/main/groovy/org/hibernate/gradle/testing/database/DatabaseMatrixPlugin.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

>>> a serious error occurred: hudson/util/DBAllocation

>>> stacktrace:

java.lang.NoClassDefFoundError: hudson/util/DBAllocation

at java.lang.Class.getDeclaredMethods0(Native Method)

at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)

at java.lang.Class.getDeclaredMethods(Class.java:1791)

at org.codehaus.groovy.vmplugin.v5.Java5.configureClassNode(Java5.java:318)

at org.codehaus.groovy.ast.ClassNode.lazyClassInit(ClassNode.java:263)

at org.codehaus.groovy.ast.ClassNode.getInterfaces(ClassNode.java:341)

at org.codehaus.groovy.ast.ClassNode.declaresInterface(ClassNode.java:929)

at org.codehaus.groovy.ast.ClassNode.implementsInterface(ClassNode.java:909)

at org.codehaus.groovy.ast.ClassNode.isDerivedFromGroovyObject(ClassNode.java:899)

at org.codehaus.groovy.classgen.AsmClassGenerator.isGroovyObject(AsmClassGenerator.java:2752)

at org.codehaus.groovy.classgen.AsmClassGenerator.visitPropertyExpression(AsmClassGenerator.java:2728)

at org.codehaus.groovy.ast.expr.PropertyExpression.visit(PropertyExpression.java:55)

at org.codehaus.groovy.classgen.AsmClassGenerator.visitAndAutoboxBoolean(AsmClassGenerator.java:4122)

at org.codehaus.groovy.classgen.AsmClassGenerator.makeCallSite(AsmClassGenerator.java:2182)

at org.codehaus.groovy.classgen.AsmClassGenerator.makeCall(AsmClassGenerator.java:2019)

at org.codehaus.groovy.classgen.AsmClassGenerator.makeCall(AsmClassGenerator.java:2005)

at org.codehaus.groovy.classgen.AsmClassGenerator.makeInvokeMethodCall(AsmClassGenerator.java:1990)

at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethodCallExpression(AsmClassGenerator.java:2342)

at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:75)

at org.codehaus.groovy.classgen.AsmClassGenerator.visitBooleanExpression(AsmClassGenerator.java:1959)

at org.codehaus.groovy.ast.expr.BooleanExpression.visit(BooleanExpression.java:40)

at org.codehaus.groovy.classgen.AsmClassGenerator.visitIfElse(AsmClassGenerator.java:913)

at org.codehaus.groovy.ast.stmt.IfStatement.visit(IfStatement.java:41)

at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:35)

at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:165)

at org.codehaus.groovy.classgen.AsmClassGenerator.visitBlockStatement(AsmClassGenerator.java:738)

at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)

at org.codehaus.groovy.classgen.AsmClassGenerator.visitIfElse(AsmClassGenerator.java:921)

at org.codehaus.groovy.ast.stmt.IfStatement.visit(IfStatement.java:41)

at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:35)

at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:165)

at org.codehaus.groovy.classgen.AsmClassGenerator.visitBlockStatement(AsmClassGenerator.java:738)

at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)

at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:101)

at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:112)

at org.codehaus.groovy.classgen.AsmClassGenerator.visitStdMethod(AsmClassGenerator.java:626)

at org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructorOrMethod(AsmClassGenerator.java:601)

at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:123)

at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethod(AsmClassGenerator.java:696)

at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1039)

at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)

at org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:276)

at org.codehaus.groovy.control.CompilationUnit$12.call(CompilationUnit.java:748)

at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:942)

at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:519)

at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:497)

at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:474)

at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:453)

at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:67)

at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:180)

at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:148)

at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:162)

Caused by: java.lang.ClassNotFoundException: hudson.util.DBAllocation

at java.net.URLClassLoader$1.run(URLClassLoader.java:202)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:190)

at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:696)

at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:793)

at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

... 52 more

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':compileGroovy'.

Cause: Forked groovyc returned error code: 1

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Simply nuke the Gradle cache from your project. I don't know if they are supposed to be in a standard location but for Hibernate the following commands did the trick

rm -fR .gradle

rm -fR buildSrc/.gradle

I wonder what will happen first, tools just working or world peace :)


Name: Emmanuel Bernard
Bio tags: French, Open Source actor, Hibernate, (No)SQL, JCP, JBoss, Snowboard, Economy
Employer: JBoss by Red Hat
Resume: LinkedIn
Team blog: in.relation.to
Personal blog: No relation to
Microblog: Twitter, Google+
Geoloc: Paris, France

Tags