[GRADLE-2967] Task artifact cache file locking issue when using Asciidoctor plugin on windows Created: 27/Nov/13  Updated: 10/Feb/17  Resolved: 10/Feb/17

Status: Resolved
Project: Gradle
Affects Version/s: 1.9
Fix Version/s: None

Type: Bug
Reporter: Gradle Forums Assignee: Unassigned
Resolution: Won't Fix Votes: 10

Issue Links:
Related
Related to GRADLE-3002 File locking issues when copy to the ... Resolved

 Description   

The origin of this post is the problem described in this [issue]([1]https://github.com/asciidoctor/asciid...). I am using the current Asciidoctor Gradle plugin to generate documentation. The plugin 'org.asciidoctor:asciidoctor-gradle-plugin:0.7.0' works fine under Unix, but not under Windows.

  • Exception is:
    org.gradle.api.UncheckedIOException: java.io.IOException: The process cannot access the file because another process has locked a portion of the file
    at org.gradle.util.hash.HashUtil.createHash(HashUtil.java:56)
    at org.gradle.util.hash.HashUtil.createHash(HashUtil.java:34)
    at org.gradle.api.internal.changedetection.state.DefaultHasher.hash(DefaultHasher.java:24)
    at org.gradle.api.internal.changedetection.state.CachingHasher.hash(CachingHasher.java:45)
    at org.gradle.api.internal.changedetection.state.DefaultFileSnapshotter$1.run(DefaultFileSnapshotter.java:48)
    at org.gradle.internal.Factories$1.create(Factories.java:22)
    at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:143)
    at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:131)
    at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:134)
    at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:74)
    at org.gradle.api.internal.changedetection.state.DefaultFileSnapshotter.snapshot(DefaultFileSnapshotter.java:44)
    at org.gradle.api.internal.changedetection.rules.InputFilesStateChangeRule.create(InputFilesStateChangeRule.java:33)
    at org.gradle.api.internal.changedetection.rules.TaskUpToDateState.(TaskUpToDateState.java:46)
    at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.getStates(DefaultTaskArtifactStateRepository.java:127)
    at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.isUpToDate(DefaultTaskArtifactStateRepository.java:69)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:283)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$1.run(DefaultTaskPlanExecutor.java:33)
    at org.gradle.internal.Factories$1.create(Factories.java:22)
    at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:214)
    at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:276)
    at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142)
    at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:78)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:31)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
    at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
    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.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:45)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:42)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.ReturnResult.execute(ReturnResult.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:71)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:69)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:59)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:45)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator.runCommand(DaemonStateCoordinator.java:186)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.doBuild(StartBuildOrRespondWithBusy.java:49)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.HandleStop.execute(HandleStop.java:36)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailure.execute(CatchAndForwardDaemonFailure.java:32)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.DefaultDaemonCommandExecuter.executeCommand(DefaultDaemonCommandExecuter.java:48)
    at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.handleCommand(DefaultIncomingConnectionHandler.java:155)
    at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.receiveAndHandleCommand(DefaultIncomingConnectionHandler.java:128)
    at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.run(DefaultIncomingConnectionHandler.java:116)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
    Caused by: java.io.IOException: The process cannot access the file because another process has locked a portion of the file
    at java.io.FileInputStream.readBytes(Native Method)
    at java.io.FileInputStream.read(FileInputStream.java:220)
    at org.gradle.util.hash.HashUtil.createHash(HashUtil.java:46)
    ... 85 more

BUILD FAILED

When I debugged the plugin it seams that the configuration phase is done right but the excecution phase doesn't start at all. When I checked out which file is locked I found out it is:

{project dir}

/.gradle/1.8/taskArtifacts/cache.properties.lock

What can I do to provide more information and to isolate the problem to either Gradle or the Asciidoctor plugin?
Kind regards, CL
----------------------------------------------------------------------------------------
[1] https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/51



 Comments   
Comment by Gradle Forums [ 27/Nov/13 ]

Occurs also with Gradle 1.9

Comment by Dan [ 22/Jan/14 ]

I also observed this problem with Gradle 1.10 and asciidoctor-gradle-plugin 0.7.0.

Comment by Christian Lipp [ 13/Feb/14 ]

I also observed this problem with Gradle 1.11 and asciidoctor-gradle-plugin 0.7.0.

Comment by Konstantin [ 05/May/14 ]

The same is with Gradle 1.12 and asciidoctor-gradle-plugin 0.7.0.

Comment by Tom Dunstan [ 18/May/14 ]

I can reproduce this at will on Windows 7 when using the Cargo plugin. Start cargo using cargoStartLocal, do some stuff, attempt to run cargoStopLocal and I get a very similar stacktrace:

org.gradle.api.UncheckedIOException: java.io.IOException: The process cannot access the file because another process has locked a portion of the file
10:42:51.456 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.internal.hash.HashUtil.createHash(HashUtil.java:57)
10:42:51.459 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.internal.hash.HashUtil.createHash(HashUtil.java:34)
10:42:51.462 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.hash.DefaultHasher.hash(DefaultHasher.java:24)
10:42:51.466 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.hash.CachingHasher.hash(CachingHasher.java:45)
10:42:51.469 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.changedetection.state.DefaultFileSnapshotter$1.run(DefaultFileSnapshotter.java:49)
10:42:51.472 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.internal.Factories$1.create(Factories.java:22)
10:42:51.475 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:187)
10:42:51.478 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:175)
10:42:51.481 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:106)
10:42:51.485 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.useCache(DefaultCacheFactory.java:193)
10:42:51.488 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:58)
10:42:51.491 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.changedetection.state.DefaultFileSnapshotter.snapshot(DefaultFileSnapshotter.java:45)
10:42:51.494 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.changedetection.rules.InputFilesStateChangeRule.create(InputFilesStateChangeRule.java:33)
10:42:51.497 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.changedetection.rules.TaskUpToDateState.<init>(TaskUpToDateState.java:46)
10:42:51.501 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.getStates(DefaultTaskArtifactStateRepository.java:126)
10:42:51.504 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.isUpToDate(DefaultTaskArtifactStateRepository.java:69)
10:42:51.507 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:52)
10:42:51.510 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
10:42:51.513 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
10:42:51.516 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
10:42:51.520 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
10:42:51.523 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
10:42:51.526 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:289)
10:42:51.529 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
10:42:51.532 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
10:42:51.535 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
10:42:51.538 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
10:42:51.541 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86)
10:42:51.544 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
10:42:51.548 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
10:42:51.551 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
10:42:51.554 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
10:42:51.557 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
10:42:51.561 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
10:42:51.564 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
10:42:51.568 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
10:42:51.571 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
10:42:51.574 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
10:42:51.577 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
10:42:51.581 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
10:42:51.584 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
10:42:51.587 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
10:42:51.590 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
10:42:51.594 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
10:42:51.597 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
10:42:51.600 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
10:42:51.603 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
10:42:51.607 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
10:42:51.610 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
10:42:51.613 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
10:42:51.616 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
10:42:51.620 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.Main.doAction(Main.java:46)
10:42:51.623 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
10:42:51.626 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.Main.main(Main.java:37)
10:42:51.629 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
10:42:51.632 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
10:42:51.636 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
10:42:51.639 [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
10:42:51.643 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.internal.hash.HashUtil.createHash(HashUtil.java:47)
10:42:51.646 [ERROR] [org.gradle.BuildExceptionReporter]        ... 56 more

While debugging it looks like Gradle is trying to read a file that the running cargo process has locked (or at least mapped). In my case it's build\cargo\cargo-domain\osgi-cache\felix\cache.lock

This is because the cargo plugin considers the cargo config directory to be an input (since you can copy stuff in there etc to change the configuration) but cargo also writes stuff there etc.

The normal workarounds that I can think of here don't work for me:

  • The normal way to force a task to run is to set outputs.upToDateWhen { false }

    , but this is an input, and there's no equivalent property on TaskInput

  • I don't see any way to exclude some files from the task's input. Really the only things that gradle should consider to be the input is the build\cargo\cargo-domain\config directory (it's a glassfish domain).

Arguably that directory shouldn't be marked as an input since you generally want to run cargo whether it's considered up to date or not. There's not much an end user can do about that though other than propose a patch to the cargo plugin.

Of course, Gradle shouldn't fall over when it can't read a file that it's trying to hash on windows - IDEs, anti-virus programs etc can all lock files at random times and Gradle should be a bit more tolerant of that - maybe fall back to e.g. timestamps?

As an aside, it would be nice if the exception rethrow in HashUtil could include a message about which file it's having problems with - at no point even running with -d did Gradle report which file was being affected. I had to clone the gradle source and run it in a debugger to work out what was going on.

Comment by Gary Hale [ 24/Jun/14 ]

Looking into the asciidoctor issue, the problem is that since 0.7.0 of asciidoctor, the baseDir property is declared as an input on AsciidoctorTask and the default value for baseDir is the project directory:

@Optional @InputDirectory File baseDir
...
AsciidoctorTask() {
...
baseDir = project.projectDir
}

The projectDir contains the cache directory, so it's considering it as part of the task inputs. So it's trying to use the cache that stores information about input state as part of what it is gathering state on. One of the files in there (cache.properties.lock) is exclusively locked at the filesystem level (implicitly by Windows) during change detection, so it is not available to be hashed and thus the error.

I can reliably reproduce the problem on Windows with the default baseDir. When I explicitly set the basedir to something else, the build succeeds.

The root issue here is that baseDir either needs to have a more sensible default (i.e. something that does not contain gradle system files) or it should not be an input to the task at all (it's not immediately clear to me why it is in the first place, but I'm not overly familiar with asciidoctor).

To the point of the previous comment, it would be immensely useful if the error message here provided the file name, so I'll look at adding that.

Comment by Andres Almiray [ 27/Jun/14 ]

This problem was reported at https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/51 and it's related to https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/60 . The latter was fixed 2 days ago. If you could please build 0.7.2-SNAPSHOT and give it a try and let us know if it solved the problem on your end.

I agree that this error is not on Gradle's side and as such suggest this ticket be closed.

Comment by Matthieu Vachon [ 07/Oct/14 ]

@Andres

I think the error is a bit on Gradle side, at least of Windows, so it should stay open.

Here a different use-case not involving a plugin in case people like me land in this issue when they are facing the java.io.IOException: The process cannot access the file because another process has locked a portion of the file error.

In the project, we are copying a .checkstyle file at the root of the project. To do this, we had a task defined like this (this creates a reproducible test case if put alone in a build.gradle file):

task copyCheckstyle(type: Copy) {
  from "path/to/.checkstyle"
  into "$project.projectDir"
}

This is failing hard on Windows with the exception message. It was very hard to understand the problem. I though that a potential workaround would be to explicitly define the file in the into property like this:

task copyCheckstyle(type: Copy) {
  from "path/to/.checkstyle"
  into "$project.projectDir/.checkstyle"
}

But this does not work as expected, because Gradle seems to expect a directory and hence, create one with the .checkstyle in it (i.e. $project.projectDir/.checkstyle/.checkstyle).

Will post a new comment if I find a good workaround.

Matt

Comment by Matthieu Vachon [ 07/Oct/14 ]

After some more research, I found GRADLE-3002. Maybe this issue could be closed and forwarded to GRADLE-3002 since the latter is more explicit about the exact problem.

Comment by Matthieu Vachon [ 07/Oct/14 ]

I added potential workaround in GRADLE-3002, the trick is to define a custom copy operation. See it here.

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 10/Feb/17 ]

Thanks again for reporting this issue. We haven't heard back from you after our inquiry from November 15th. We are closing this issue now. Please create an issue on GitHub if you still feel passionate about getting it resolved.

Generated at Wed Jun 30 12:36:16 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.