在执行Gradle任务之前获取用户选择

Vik*_*Vik 4 gradle

我正在将我们的Capistrano部署应用程序切换到Gradle.

这里要求使脚本用户具有交互性.

我坚持在任务之间提供用户输入.

task('hello') << {
    println "hello" }

task('copy', type: Copy) {
    some_user_input = prompt("Are you sure to copy this file. ") ... // Here wants something like that
    if(some_user_input==true){
      from(file('srcDir'))
      into(buildDir)
    } }
Run Code Online (Sandbox Code Playgroud)

我正在寻找这个问题的解决方案.如果您知道这种方式,请告诉我.

提前致谢 .

Ben*_*hko 16

Gradle允许您在构建脚本中使用现有的Ant任务.您可以使用[Ant输入任务] [1]来实现此目的:

ant.input(message: 'Are you sure to copy this file?', validargs: 'y,n', addproperty: 'doDeleteFile')

if(ant.doDeleteFile == 'y') {
    // Call copy task
}
Run Code Online (Sandbox Code Playgroud)

请注意,与System.console()此不同,它也适用于Gradle守护程序(在Linux上测试).


tho*_*dge 0

您尝试过使用控制台吗?像这样的东西:

if (System.console().readLine().toLowerCase() == 'y') ...
Run Code Online (Sandbox Code Playgroud)