Unable to generate tar with gradle - cache.properties locked

Unable to generate tar with gradle because of locked file. This is due to the fact the .gradle directory is created in the same directory as project dir. I tried setting buildDir to outside of the project dir but .gradle directory and subsequent cache.properties are created which causes the lock

org.gradle.api.UncheckedIOException: Failed to capture snapshot of input files for task ‘buildTar’ during up-to-date check. See stacktrace for details.
at org.gradle.api.internal.changedetection.rules.TaskUpToDateState.(TaskUpToDateState.java:59)
at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.getStates(DefaultTaskArtifactStateRepository.java:126)
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:306)
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.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
Caused by: org.gradle.api.UncheckedIOException: Failed to create MD5 hash for file C:…gradle\2.3\taskArtifacts\cache.properties.lock.
at org.gradle.internal.hash.HashUtil.createHash(HashUtil.java:37)
at org.gradle.api.internal.hash.DefaultHasher.hash(DefaultHasher.java:24)
at org.gradle.api.internal.changedetection.state.CachingFileSnapshotter.snapshot(CachingFileSnapshotter.java:46)
at org.gradle.api.internal.changedetection.state.CachingFileSnapshotter.snapshot(CachingFileSnapshotter.java:27)
at org.gradle.api.internal.changedetection.state.DefaultFileCollectionSnapshotter$1.run(DefaultFileCollectionSnapshotter.java:56)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:192)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:175)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:106)
at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.useCache(DefaultCacheFactory.java:187)
at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:60)
at org.gradle.api.internal.changedetection.state.DefaultFileCollectionSnapshotter.snapshot(DefaultFileCollectionSnapshotter.java:52)
at org.gradle.api.internal.changedetection.rules.TaskUpToDateState.(TaskUpToDateState.java:55)
… 13 more
Caused by: java.io.IOException: The process cannot access the file because another process has locked a portion of the file.
at org.gradle.internal.hash.HashUtil.createHash(HashUtil.java:50)
at org.gradle.internal.hash.HashUtil.createHash(HashUtil.java:34)
… 25 more

Thank you.

What is the purpose of the tar file you’re trying to produce? Wouldn’t it make more sense to just exclude the “.gradle” directory from the tar file?

David, thank you for the reply. Yes excluding the .gradle dir is alternative that worked. I am still lookng for a way to have .gradle directory generated to location outside of the project dir. I was hoping that setting the buildDir to another location would create the .gradle directory there but it did not. But then again I am not sure if that is one of the intent of the buildDir.

Thank you.

This can be done with the --project-cache-dir command line argument.

Mark, thank you. That works.