Set fileMode for *.sh When Copying Files To Tar By

2019-08-12 14:21发布

问题:

If I have a gradle file like this

apply plugin: 'distribution'

version = '1.2'
 distributions {
    custom {}
}

By convention, all of the files in the “src/custom/dist” directory will automatically be included in the distribution. https://docs.gradle.org/current/userguide/distribution_plugin.html

What if I want to set the fileMode on some of these files?

If I just specify the fileMode it doesn't do anything.

  into("") {
    from "src/custom/scripts"
    fileMode 0755
  }

EDIT: If I put the scripts in another dir and explicitly copy them (rather than them being copied by convention, the code below works.

distributions {
  custom {
    baseName = 'myApp'
    contents {
      into("") {
        from "src/external/scripts"
        fileMode 0755
      }
    }
  }

I am wondering if it is possible to have the files in the conventional place but change the attributes on some of the files.

回答1:

Following @RaGe link I came up with this:

distributions {
  custom {
    baseName = 'myApp'
    contents {
      //Other stuff
      eachFile { file ->
        if(file.getName().endsWith(".sh")) {
          file.setMode(0755)
      }
    }
  }


标签: gradle