5

Using Gradle to build an application, I created a "src/dist/bin" folder for a shutdown.sh script to be packaged in the distribution zip. How can I set the fileMode so it can be executed? I already know how to set the fileMode using the copy task but in that case the script is copied by the distribution plugin.

Gradle Application plugin

Thanks

Martin P.
  • 654
  • 8
  • 18

1 Answers1

3

It should be the same as in any Copy Task because distribution is using CopySpec. I use code similar to the following. I put the scripts to a different folder.

distributions {
    main {
        contents {
            into('bin') {
                from {
                    'src/main/customscripts/start.sh'
                }
                fileMode 0755
            }
        }
    }
}
MartinTeeVarga
  • 10,478
  • 12
  • 61
  • 98
  • This solution works and I had to move the script location because if I kept it in the "src/dist/bin" folder it's included twice in the distribution tar file. Verify it with Gradle version 2.4. – Martin P. Oct 20 '15 at 18:25
  • It needs `duplicatesStrategy = 'exclude'` too, see http://stackoverflow.com/questions/33489384/gradle-creating-duplicate-start-scripts-into-bin-directory – ben3000 Nov 12 '15 at 09:14
  • 1
    ...and as I've discovered since, `fileMode` only works for me if I avoid using `duplicatesStrategy` because it is the second copy that has the correct `fileMode` and yet this copy is the one that gets deleted if I use `duplicatesStrategy`. – ben3000 Nov 13 '15 at 01:55
  • 1
    Will this work even if you build on a Windows machine? – Karl Ivar Dahl Mar 17 '16 at 14:52
  • @KarlIvarDahl yes, in fact I use it because the build happens on a Windows machine – MartinTeeVarga Mar 17 '16 at 22:31