Gradle - Exec (Command execution)

About

How to execute a command with the exec task type:

Example by DSL

groovy

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

Kotlin

task<Exec>("echoNico") {
    workingDir("$projectDir")
    if (System.getProperty("os.name").toLowerCase().contains("windows")) {
        commandLine("cmd", "/c", "echo", "nico")
    } else {
        commandLine( "sh", "-c", "echo", "nico")
    }
}
  • Execution
gradle echoNico

Powered by ComboStrap