Build failure with Failed to capture snapshot of input files for task 'war' during up-to-date check

I’m new to gradle and inherited a build. I’m building the code through jenkins CI and invoking gradle 2.3. The tasks I’m calling are “clean war”. It appears to go through all of the dependencies ok, then it goes into a series of steps around acquiring a lock and setting up some cache files in a .gradel/2.3 directory in my jenkins workspace. I then get this error:

12:37:24.737 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[main,5,main]] finished, busy: 5.943 secs, idle: 0.0 secs
12:37:24.737 [ERROR] [org.gradle.BuildExceptionReporter]
12:37:24.737 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
12:37:24.737 [ERROR] [org.gradle.BuildExceptionReporter]
12:37:24.737 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
12:37:24.737 [ERROR] [org.gradle.BuildExceptionReporter] Failed to capture snapshot of input files for task ‘war’ during up-to-date check. See stacktrace for details.
12:37:24.737 [ERROR] [org.gradle.BuildExceptionReporter] > Failed to create MD5 hash for file E:\programs\jenkins\jobs\IDA\jobs\ICM\jobs\2.0\jobs\CI.gradle\workspace\caches\modules-2\modules-2.lock.
12:37:24.737 [ERROR] [org.gradle.BuildExceptionReporter]
12:37:24.737 [ERROR] [org.gradle.BuildExceptionReporter] * Try:
12:37:24.737 [ERROR] [org.gradle.BuildExceptionReporter] Run with --stacktrace option to get the stack trace.
12:37:24.737 [LIFECYCLE] [org.gradle.BuildResultLogger]
12:37:24.737 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED

Any idea what is going wrong here?

One thing I notice is if I use the .gradle folder under the user running the build and do not use the local workspace in jenkisn to create a .gradle folder, then the build works. If I use the .gradle folder under the user’s home, it does not. Any idea why?

can you run your build with --stacktrace and share your stacktrace?

16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] Failed to capture snapshot of input files for task 'war' during up-to-date check.  See stacktrace for details.
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] > Failed to create MD5 hash for file E:\programs\jenkins\jobs\IDA\jobs\ICM\jobs\2.0\jobs\CI.gradle\workspace\caches\modules-2\modules-2.lock.
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is:
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.UncheckedIOException: Failed to capture snapshot of input files for task 'war' during up-to-date check.  See stacktrace for details.
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.changedetection.rules.TaskUpToDateState.<init>(TaskUpToDateState.java:59)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.getStates(DefaultTaskArtifactStateRepository.java:126)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.isUpToDate(DefaultTaskArtifactStateRepository.java:69)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:52)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:306)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:169)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.Main.doAction(Main.java:33)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.gradle.api.UncheckedIOException: Failed to create MD5 hash for file E:\programs\jenkins\jobs\IDA\jobs\ICM\jobs\2.0\jobs\CI.gradle\workspace\caches\modules-2\modules-2.lock.
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.internal.hash.HashUtil.createHash(HashUtil.java:37)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.hash.DefaultHasher.hash(DefaultHasher.java:24)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.changedetection.state.CachingFileSnapshotter.snapshot(CachingFileSnapshotter.java:46)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.changedetection.state.CachingFileSnapshotter.snapshot(CachingFileSnapshotter.java:27)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.changedetection.state.DefaultFileCollectionSnapshotter$1.run(DefaultFileCollectionSnapshotter.java:56)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.internal.Factories$1.create(Factories.java:22)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:192)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:175)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:106)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.useCache(DefaultCacheFactory.java:187)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:60)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.changedetection.state.DefaultFileCollectionSnapshotter.snapshot(DefaultFileCollectionSnapshotter.java:52)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.api.internal.changedetection.rules.TaskUpToDateState.<init>(TaskUpToDateState.java:55)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	... 44 more
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.io.IOException: The process cannot access the file because another process has locked a portion of the file
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.internal.hash.HashUtil.createHash(HashUtil.java:50)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.internal.hash.HashUtil.createHash(HashUtil.java:34)
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter] 	... 56 more
16:34:52.484 [ERROR] [org.gradle.BuildExceptionReporter]

An additional note. In this case, I’m calling the war task in order to merely package code. There is no compiling of classes.

Where I’ve seen this behavior before, and which matches the behavior you are talking about, is when the .gradle directory is somehow being added to the inputs of the task. The .gradle directory is where the up-to-date checking stores the file hashes in between builds. Because windows uses mandatory file locking, once the up-to-date check locks this file, it can’t then later open it to hash the file, which is where this error comes from. When you use a different .gradle directory, it isn’t trying to hash the same files where it is storing the up-to-date information, so it’s not an issue.

The root issue is that .gradle should not be a part of what it is trying to snapshot for the up-to-date checks. Take a look at what the inputs are for the war task (i.e. ‘from’ statements). I’m betting one of them is ‘projectDir’ or something similar that’s capturing the project’s .gradle directory.

Gary:

I think that you are referring to the from ‘.’ listed below. It sounds like you are saying that the .gradle folder should be outside of the war task root folder structure (sorry, I am new to gradle so I may not have the terminology correct.) what I’m thinking of doing is to move all of the workpscae to a subfolder and invoking the build.gradle file from one level up (the root of the workspace). I’m hoping that it will then create the .gradle folder at the root and not the subfolder. I will try and test. Can you tell me if the exclude statements are purely for packaging?

war {
from '.'
exclude 'build’
exclude '.gradle’
exclude 'build.gradle’
exclude 'gradle’
exclude 'gradlew’
exclude ‘gradlew.bat’
}

Yeah, that’s what’s doing it. I would have thought the exclude would prevent ‘.gradle’ from being considered during up-to-date checking, but maybe there is something odd going on. In any event, the way you are doing it is a bit of an anti-pattern - moving your web content to a sub directory is the right move. The conventional location is ‘src/main/webapp’. If you move it there, then you probably wouldn’t have to do any configuration on the war task at all.

I ran into the same problem - a source distribution packager was packaging root project folder and including the .gradle folder. This answer helped very much. Thanks very much!

wrt exclude ‘.gradle’, I found that I needed 'exclude ‘.gradle/**’.