如何将参数从Gradle exec任务传递到命令行

Nid*_*ain 2 batch-file sh command-line-arguments gradle build.gradle

我试图用gradle exec任务连接一个bat和sh文件(取决于正在运行的操作系统)。但是我无法弄清楚如何从exec任务向bat / sh发送参数。

task testing(type:Exec) {
    workingDir '.'

    if (System.properties['os.name'].toLowerCase().contains('windows')) {
        if ( project.hasProperty("arg1") ) {
            println arg1
            args arg1
            commandLine 'cmd', '/c', 'run.bat'
        }else{
            commandLine 'cmd', '/c', 'run.bat'
        }
   }else {
        if ( project.hasProperty("arg1") ) {
            args arg1
            commandLine './run.sh'
        }else{
            commandLine './run.sh'
        }
   }
}
Run Code Online (Sandbox Code Playgroud)

如果我以:运行该任务gradle testing -Parg1=test,在中println arg1,它将打印测试

但是如何将这个测试作为bat / sh文件的参数传递。

Dan*_*aub 5

通过传递arg commandLine

视窗

commandLine 'cmd', '/c', 'run.bat' ,arg1
Run Code Online (Sandbox Code Playgroud)

Linux / Mac

commandLine './run.sh' , arg1
Run Code Online (Sandbox Code Playgroud)