Execute shell script in Gradle

前端 未结 6 437
北荒
北荒 2020-12-07 17:20

I have a gradle build setup at the beginning of which I want to execute a shellscript in a subdirectory that prepares my environment.

task build << {
         


        
6条回答
  •  我在风中等你
    2020-12-07 18:09

    A more generic way of writing the exec task, but portable for Windows/Linux, if you are invoking a command file on the PATH:

    task myPrebuildTask(type: Exec) {
        workingDir "$projectDir/mySubDir"
        if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
            commandLine 'cmd', '/c', 'mycommand'
        } else {
            commandLine 'sh', '-c', 'mycommand'
        }
    }
    

    This doesn't directly address the use case for the OP (since there is script file in the working directory), but the title of the question is more generic (and drew me here), so it could help someone maybe.

提交回复
热议问题