gradle / kotlin-dsl-samples

Samples builds using the Gradle Kotlin DSL
https://gradle.org/kotlin/
Other
3.71k stars 434 forks source link

file permission not correctly set when using `Copy` task #1412

Closed mochadwi closed 4 years ago

mochadwi commented 4 years ago

In this samples, I couldn't find any samples regarding file permission when using Copy or working with files related

My kotlin gradle custom code here:

val deletePreviousGitHOok by tasks.registering(Delete::class) {
    group = "utils"
    description = "Deleting previous githook"

    val preCommit = "${rootProject.rootDir}/.git/hooks/pre-commit"
    val prePush = "${rootProject.rootDir}/.git/hooks/pre-push"
    if (file(preCommit).exists() && file(prePush).exists()) {
        delete(preCommit, prePush)
    }
}

val installGitHook by tasks.registering(Copy::class) {
    group = "utils"
    description = "Adding githook to local working copy, this must be run manually"

    dependsOn(deletePreviousGitHOok)
    from("${rootProject.rootDir}/pre-commit", "${rootProject.rootDir}/pre-push")
    into("${rootProject.rootDir}/.git/hooks")
    fileMode = 777
}

Expected Behavior

file permission set correctly to 777

Current Behavior

line fileMode = 777 doesn't set the permission correctly, see image below: Screen Shot 2020-06-23 at 11 07 15 AM

The git console: Screen Shot 2020-06-23 at 11 08 38 AM

Context

Is there any alternative or samples to modify file permission when working with files with kotlin gradle?

Steps to Reproduce (for bugs)

Your Environment

mochadwi commented 4 years ago

SOLVED:

https://kotlinlang.org/docs/reference/basic-types.html#literal-constants

Using binary representations works instead.

   eachFile {
        fileMode = 0b111101101
    }