zipTree unable to overwrite temporary read-only files

Thanks Peter, I will explain it better with a simple example.

Imagine that this is the layout of the project:


where the file “lib/” is a zip/jar/whatever compressed archive including a readonly file (in the example, it contains simply a file) and that at least one of the file inside the zip is a read only file.

This is the build.gradle:

apply plugin: "java"
  dependencies {
 runtime files("lib/")
  task fatJar(type: Jar) {
 from {
   configurations.runtime.filter {
  }.collect {
 from sourceSets.main.output
 classifier = 'fatJar'

Now, if you run “gradle fatJar”, gradle will expand the zip file in a temporary folder, and then compress it into the fat jar. Fine, it works as expected. This is the command output:

:processResources UP-TO-DATE

Now, for a second time, try to run “gradle fatJar”. This time the zip file will be expanded again OVER the previously extracted folder, but since the property file was read-only, gradle will fail complaining that:

:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
  FAILURE: Build failed with an exception.
  * What went wrong:
Could not expand ZIP '/home/larzeni/.eclipseWorkspace/gradleReadOnlyTest/lib/'.
  * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

And if you go through using --debug option, the problem cause can be traced to:

org.gradle.api.GradleException: Could not copy zip entry /home/larzeni/.eclipseWorkspace/gradleReadOnlyTest/lib/! to '/home/larzeni/.eclipseWorkspace/gradleReadOnlyTest/build/tmp/expandedArchives/zipped_readonly_property_file.zip_67dpdot7v9plqhjmhvtlkg3gjd/'

That is, gradle cannot overwrite a zip that includes a read-only file. Obviously if you run gradle clean , the tmp/zip-expanded directory will be removed and the build will work fine again.

Possible solutions coud be: A) do not re-expand a zipped file which was already expanded if it’s not changed or, B) delete the temporary dir that contains the expanded zip after the build.

I hope now the problem is more understandable.

If you want, I’ve put the files for the example at the following link:

Thanks for your help!