Sporadic failures due to "Could not load compiled classes for initialization script 'init.gradle' from cache"

I have a CI build that always uses an init script. Every once in a while the build fails with the following error message:

Starting Build
  FAILURE: Build failed with an exception.
  * What went wrong:
Could not load compiled classes for initialization script 'init.gradle' from cache.

This is can be fixed by deleting the workspace.

I’m running milestone 9 on linux. Gradle home is set to a local directory.

Can you run with the ‘-s’ (show stacktrace) switch and provide the exception trace please.

I’ve turned on stacktraces on the CI server builds and will post the stacktrace next time the problem recurs.

org.gradle.api.GradleException: Could not load compiled classes for initialization script '/tmp/hudson/workspace/job/gradle/hudson.init.gradle' from cache.
 at org.gradle.groovy.scripts.internal.DefaultScriptCompilationHandler.loadFromDir(DefaultScriptCompilationHandler.java:175)
 at org.gradle.groovy.scripts.internal.FileCacheBackedScriptClassCompiler.compile(FileCacheBackedScriptClassCompiler.java:54)
 at org.gradle.groovy.scripts.internal.ShortCircuitEmptyScriptCompiler.compile(ShortCircuitEmptyScriptCompiler.java:35)
 at org.gradle.groovy.scripts.internal.CachingScriptClassCompiler.compile(CachingScriptClassCompiler.java:36)
 at org.gradle.groovy.scripts.DefaultScriptCompilerFactory$ScriptCompilerImpl.compile(DefaultScriptCompilerFactory.java:60)
 at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:114)
 at org.gradle.configuration.DefaultInitScriptProcessor.process(DefaultInitScriptProcessor.java:37)
 at org.gradle.initialization.InitScriptHandler.executeScripts(InitScriptHandler.java:41)
 at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:128)
 at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:110)
 at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:78)
 at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:42)
 at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:28)
 at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:32)
 at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:21)
 at org.gradle.launcher.cli.CommandLineActionFactory$WithLoggingAction.execute(CommandLineActionFactory.java:302)
 at org.gradle.launcher.cli.CommandLineActionFactory$WithLoggingAction.execute(CommandLineActionFactory.java:286)
 at org.gradle.launcher.Main.doAction(Main.java:48)
 at org.gradle.launcher.exec.EntryPoint$1.execute(EntryPoint.java:53)
 at org.gradle.launcher.exec.EntryPoint$1.execute(EntryPoint.java:51)
 at org.gradle.launcher.exec.Execution.execute(Execution.java:28)
 at org.gradle.launcher.exec.EntryPoint.run(EntryPoint.java:39)
 at org.gradle.launcher.Main.main(Main.java:39)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.gradle.launcher.ProcessBootstrap.runNoExit(ProcessBootstrap.java:51)
 at org.gradle.launcher.ProcessBootstrap.run(ProcessBootstrap.java:33)
 at org.gradle.launcher.GradleMain.main(GradleMain.java:24)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33)
 at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:124)
 at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:53)
Caused by: java.lang.ClassNotFoundException: hudson_init_1g66oc1gavjiouoobrf5lu8if0
 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:307)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
 at org.gradle.groovy.scripts.internal.DefaultScriptCompilationHandler.loadFromDir(DefaultScriptCompilationHandler.java:173)
 ... 36 more

Anyone?

I thought I should mention that this problem has been popping every once in a while through a number of gradle releases – it is not new to milestone 9.

I’ve raised this as issue GRADLE-2249.

I’m unsure what’s going on at this time.

Hello David, I would like to reproduce your problem. Can you give some more details about your setup and how you use gradle with your CI server.

  • What ci server do you use? - How do you invoke gradle in your build jobs? CI plugin, bash, gradle wrapper? - Have you multiple jobs on your CI that use this init script? - where is that init script located to?

  • Do you reference this init script via -i or do you put in the init.d folder of your gradle distribution? - Do you use different gradle versions on your CI?

regards, René

Please let me know if you have any additional questions.

  • What ci server do you use?

Jenkins

  • How do you invoke gradle in your build jobs? CI plugin, bash, gradle wrapper?

I call it with bash. Here is a sample command line:

./gradlew --full-stacktrace --info --init-script gradle/hudson.init.gradle --gradle-user-home /tmp/hudson/workspace/job/gradle/gradle-user-home clean build

  • Have you multiple jobs on your CI that use this init script?

No, only one. There is complete separation of job workspaces; all sources and output are exclusive to that Jenkins job.

  • where is that init script located to?

Inside the checked out sources.

  • Do you use different gradle versions on your CI?

No.

Hello, we have the same problem on Bamboo.