org.gradle.api.UncheckedIOException: Failed to capture snapshot of input files

Hi

How the exception below could be avoided/bypassed:

* What went wrong:
Failed to capture snapshot of input files for task 'compileJjtree' property 'inputDirectory' during up-to-date check.
> Failed to create MD5 hash for file 'C:\Git\SPLC\SPLC\SPLC.VC.VC.opendb'.

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.UncheckedIOException: Failed to capture snapshot of input files for task 'compileJjtree' property 'inputDirectory' during up-to-date check.
        at org.gradle.api.internal.changedetection.rules.AbstractNamedFileSnapshotTaskStateChanges.buildSnapshots(AbstractNamedFileSnapshotTaskStateChanges.java:89)
        at org.gradle.api.internal.changedetection.rules.AbstractNamedFileSnapshotTaskStateChanges.<init>(AbstractNamedFileSnapshotTaskStateChanges.java:54)
        at org.gradle.api.internal.changedetection.rules.InputFilesTaskStateChanges.<init>(InputFilesTaskStateChanges.java:28)
        at org.gradle.api.internal.changedetection.rules.TaskUpToDateState.<init>(TaskUpToDateState.java:55)
        at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.getStates(DefaultTaskArtifactStateRepository.java:164)
        at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.isUpToDate(DefaultTaskArtifactStateRepository.java:79)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
        at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
        at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:196)
        at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:193)
        at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:193)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
        at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
        at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:173)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:244)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:217)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:33)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:210)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:174)
        at org.gradle.launcher.Main.doAction(Main.java:33)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:60)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:37)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: org.gradle.api.UncheckedIOException: Failed to create MD5 hash for file 'C:\Git\SPLC\SPLC\SPLC.VC.VC.opendb'.
        at org.gradle.api.internal.hash.DefaultFileHasher.hash(DefaultFileHasher.java:48)
        at org.gradle.api.internal.changedetection.state.CachingFileHasher.snapshot(CachingFileHasher.java:79)
        at org.gradle.api.internal.changedetection.state.CachingFileHasher.snapshot(CachingFileHasher.java:68)
        at org.gradle.api.internal.changedetection.state.CachingFileHasher.hash(CachingFileHasher.java:60)
        at org.gradle.api.internal.changedetection.state.AbstractFileCollectionSnapshotter.snapshot(AbstractFileCollectionSnapshotter.java:97)
        at org.gradle.api.internal.changedetection.rules.AbstractNamedFileSnapshotTaskStateChanges.buildSnapshots(AbstractNamedFileSnapshotTaskStateChanges.java:87)
        ... 63 more
Caused by: java.io.FileNotFoundException: C:\Git\SPLC\SPLC\SPLC.VC.VC.opendb (Le processus ne peut pas accÚder au fichier car ce fichier est utilisÚ par un autre processus)
        at com.google.common.io.Files$FileByteSource.openStream(Files.java:126)
        at com.google.common.io.Files$FileByteSource.openStream(Files.java:116)
        at com.google.common.io.ByteSource.copyTo(ByteSource.java:234)
        at com.google.common.io.Files.copy(Files.java:423)
        at org.gradle.api.internal.hash.DefaultFileHasher.hash(DefaultFileHasher.java:45)
        ... 68 more

Could you please provide some sample code that reproduces the issue?

The file below is an utility file opened in exclusive mode by VS2015.

when VS2015 is closed, there is no exception, when VS2015 is opened on a VS projet within the directory where gradle is building the build.gradle script, the exception appears.
The project SPLC can be wiewed here: https://github.com/jtb-javacc/SPLC

Hey Francis,

The issue comes from how compileJjtree is configured more specifically the value used for inputDirectory. The value is set to projectDir which ends up been passed to the SourceTask.setSource. By default, any SourceSet related configuration in Gradle will grab everything recursively under the source directory specified. In most case, this is fine as the folder is deep and isolated in the project’s folder layout. Once in awhile, more often with legacy folder structure, the configuration requires the source directory to be closer to the project root folder. In those case, a lot more files could be included and, often but not always, those files are specified as input to a task. Gradle will honor those input by creating a snapshot for future execution run. In that scenario, two problems will occur.

  1. Input snapshot will fail. Just like your current failure, the task will try to snapshot files that are unrelated to the task’s job. Those files could be system files or legitimately locked by another process.
  2. Input snapshot will succeed but the task will never be up-to-date. A folder could be included in the snapshot that happens to be the output of another task that runs before (or after) your task. This will cause Gradle to wrongly detect a change for a task as some of the “input” are changed between runs. This will kind of happen in your case as the compileJjtree will snapshot the build folder which changes as more task are run.

That been said, to fix your problem, you will have to narrow down the amount of files included in compileJjtree through include and exclude methods from SourceTask. If the filtering pattern becomes too complicated, you can always move the inputDirectory somewhere more isolated and let Gradle glob everything.

Don’t hesitate to ask more questions,

Daniel

Thanks for your detailled explanation. Reducing the scope of the compileJjtree task solves the problem.

Hi Daniel_L, what you mean with that directory? And where I can put it?
Sorry if is an stupid question… Thank you!
I have the problem of the MD5 file:
Error:Execution failed for task ‘:androidsupportv7palette:compileReleaseJavaWithJavac’.

Failed to create MD5 hash for file ‘/home/fran/Documents/mobilitapp/androidsupportv7palette/libs/android-support-v7-palette.jar’.

It is driving me crazy…

@fmedmon Could you give a bit more context? A build scan could help with this. It could be a different problem than the previous one. In general, it could mean you have a SourceSet configured in a way that includes more files than required. If that is the case, start by looking at the code that set up your SourceSet.

fran@fran-pc:~/AndroidStudioProjects/mobilitapp$ gradle build --scan

FAILURE: Build failed with an exception.

  • Where:
    Build file ‘/home/fran/AndroidStudioProjects/mobilitapp/androidsupportv7palette/build.gradle’ line: 1

  • What went wrong:
    A problem occurred evaluating project ‘:androidsupportv7palette’.

Failed to apply plugin [id ‘com.android.library’]
Minimum supported Gradle version is 3.3. Current version is 2.10. If using the gradle wrapper, try editing the distributionUrl in /home/fran/AndroidStudioProjects/mobilitapp/gradle/wrapper/gradle-wrapper.properties to gradle-3.3-all.zip

  • 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: 4.228 secs

But I have a Gradle 3.3… I don’t know if the scan works like this… Thank you and sorry