GradleException: Could not load compiled classes for build file. Fails on all scripts, even after removing cache

I’ve recently been getting showstopping build errors on all tasks, all build scripts I try to run on my machine, due to this error.

I’ve tried to research this problem and see that people mention clearing the user profile .gradle dir as a fix, but it does not help me. The error does not change.

Gradle 1.11

Build time:

2014-02-11 11:34:39 UTC Build number: none Revision:

a831fa866d46cbee94e61a09af15f9dd95987421

Groovy:

1.8.6 Ant:

Apache Ant™ version 1.9.2 compiled on July 8 2013 Ivy:

2.2.0 JVM:

1.7.0_51 (Oracle Corporation 24.51-b03) OS:

Windows 7 6.1 amd64

Here’s an example of the problem:

C:\temp\gradle\test>gradle tasks
  FAILURE: Build failed with an exception.
  * What went wrong:
A problem occurred configuring root project 'test'.
> Could not load compiled classes for build file 'C:\temp\gradle\test\build.gradle' from cache.
  * 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: 6.367 secs

and here’s a stacktrace:

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'test'.
        at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:79)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:57)
        at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:507)
        at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:82)
        at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:31)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
        at org.gradle.launcher.Main.doAction(Main.java:46)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at org.gradle.launcher.Main.main(Main.java:37)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: org.gradle.api.GradleException: Could not load compiled classes for build file 'C:\temp\gradle\test\build.gradle' from cache.
        at org.gradle.groovy.scripts.internal.DefaultScriptCompilationHandler.loadFromDir(DefaultScriptCompilationHandler.java:176)
        at org.gradle.groovy.scripts.internal.FileCacheBackedScriptClassCompiler.compile(FileCacheBackedScriptClassCompiler.java:69)
        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:57)
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:171)
        at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:38)
        at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:25)
        at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
        ... 25 more
Caused by: java.lang.ClassNotFoundException: build_6fahaj53d4pdh2pq90o4lu9vl2
        at org.gradle.groovy.scripts.internal.DefaultScriptCompilationHandler.loadFromDir(DefaultScriptCompilationHandler.java:170)
        ... 34 more
Caused by: java.io.FileNotFoundException: C:\Users\r6pw2\.gradle\caches.11\scripts\build_6fahaj53d4pdh2pq90o4lu9vl2\ProjectScript\no_buildscript\classes\build
_6fahaj53d4pdh2pq90o4lu9vl2.class (Access is denied)
        ... 35 more

Any help would be greatly appreciated. I’m not sure why this stuff is now breaking as it used to work before, without any build.gradle, gradle runtime, or JVM changes. I’ve tried removing both the user profile .gradle and the project .gradle dirs, but the error remains.

Sounds like a file permission problem. Does the mentioned class file for which “access is denied” exist?

It does exist, yes. And my user has access to read/edit it.

In this directory, I see for example:

C:\Users\r6pw2.gradle\caches\1.11\scripts\build_7jsb72rtc4k4m5e12ik1ap5qqa\ProjectScript\no_buildscript\classes>dir

Volume in drive C is OSDisk

Volume Serial Number is 1C21-D205

Directory of C:\Users\r6pw2.gradle\caches\1.11\scripts\build_7jsb72rtc4k4m5e12ik1ap5qqa\ProjectScript\no_buildscript\classes

03/04/2014 11:20 AM

. 03/04/2014 11:20 AM

… 03/04/2014 11:18 AM

3,289 build_7jsb72rtc4k4m5e12ik1ap5qqa$_run_closure1.class 03/04/2014 11:18 AM

3,452 build_7jsb72rtc4k4m5e12ik1ap5qqa$_run_closure1_closure6.class 03/04/2014 11:18 AM

3,240 build_7jsb72rtc4k4m5e12ik1ap5qqa$_run_closure2.class 03/04/2014 11:18 AM

3,444 build_7jsb72rtc4k4m5e12ik1ap5qqa$_run_closure3.class 03/04/2014 11:18 AM

3,288 build_7jsb72rtc4k4m5e12ik1ap5qqa$_run_closure4.class 03/04/2014 11:18 AM

3,293 build_7jsb72rtc4k4m5e12ik1ap5qqa$_run_closure5.class 03/04/2014 11:18 AM

3,333 build_7jsb72rtc4k4m5e12ik1ap5qqa$_run_closure5_closure7.class 03/04/2014 11:18 AM

3,258 build_7jsb72rtc4k4m5e12ik1ap5qqa$_run_closure5_closure7_closure8.class 03/04/2014 11:18 AM

10,141 build_7jsb72rtc4k4m5e12ik1ap5qqa.class

9 File(s)

36,738 bytes

2 Dir(s) 257,536,319,488 bytes free

when the exception contains: Caused by: java.io.FileNotFoundException: C:\Users\r6pw2.gradle\caches\1.11\scripts\build_7jsb72rtc4k4m5e12ik1ap5qqa\ProjectScript\no_buildscript\classes\build _7jsb72rtc4k4m5e12ik1ap5qqa.class (Access is denied)

Hard to say from here, but “access is denied” sounds like a file permission problem to me.

Ok, I agree, that is what it sounds like.

Thanks for the insight; I’ll keep digging.

I’ve tried just about everything I can think of and haven’t gotten anywhere. I’ve tried other Gradle versions (1.5), other JVM (1.6), still get this same error.

Such a strange problem; last time I tried this everything worked fine. If anyone has any more diagnostic suggestions, I’d greatly appreciate it!

I’m starting to wonder if some security software on my machine is interfering, but have no way I can think of to verify this.

I’m happy to report that the problem was indeed due to security software running on my machine. Apparently it was blocking the JVM from “running” random files it didn’t know about.