Bitten by the default permissions / reproducible a...
# community-support
c
Bitten by the default permissions / reproducible archive changes in Gradle 9 -
distZip
no longer pulls the filesystem permissions. We could force that via
useFileSystemPermissions
but seems cleaner to set the explicit/desired permissions in the build script. But doing that seems to be incompatible with the configuration cache. Seems like
filePermissions
is incompatible with configuration cache?
Copy code
plugins {
    application
}

tasks.named<Zip>("distZip") {
    // setting permissions here fails as properties are finalized already
//    filesMatching("**/*") {
//        filePermissions {
//            unix("rwxr-xr-x")
//        }
//    }
}

distributions {
    main {
        contents {
            filesMatching("bin/**") {
                // simply adding "filePermissions" fails
                // Cause: class org.gradle.api.internal.file.copy.DefaultCopySpec cannot be cast to class org.gradle.api.file.FileCollection (org.gradle.api.internal.file.copy.DefaultCopySpec and org.gradle.api.file.FileCollection are in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @3043fe0e)
                filePermissions {
                    unix("rwxr-xr-x")
                }
            }
        }
    }
}
Disabling CC results in
The value for property 'filePermissions' is final and cannot be changed any further.
when configuring permission on the distribution contents. This seems like a common use case - adjust executable permission on distribution files - surprised this is problematic. On Gradle 9.2.0.
v
It is not problematic if you don't do it wrongly. 😄
filePermissions
is a property of
CopyProcessingSpec
and thus
Copy
. In the
filesMatching
you should configure the
FileCopyDetails
that is the context there. But you configure the outer one (the task in the upper the copy spec in the lower case). Use
permissions
instead of
filePermissions
, that is on the
FileCopyDetails
and works without problems. 🙂
Not too obvious of course
A little trick, I like to use
this.<Ctrl+Space>
to see what is available on the actual
this
in the inner-most scope and then after completing remove the
this.
for better readability. Without the
this.
you also get suggestions for the outer scope `this`es.
c
ohhh the footguns. thanks for clarifying that, I was misled by the docs which only address tasks and not CopySpec.
v
It's not about task vs. copyspec, those are both
filePermissions
.
It is copyspec (the task is a copyspec too) vs. the filecopydetails in the
filesMatching
👍 1