Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get user choice before execution of Gradle task

Tags:

gradle

I am switching our application for Capistrano deployment to Gradle .

Here requirement to make the script user interactive .

I am stuck to provide the user input in between task .

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)
    } }

I am searching for the solution of such issue . If you know about such way than please let me know .

Thanks in advance .

like image 592
Vik Avatar asked Nov 28 '11 14:11

Vik


1 Answers

Gradle lets you use existing Ant tasks within your build script. You could use the [Ant input task][1] to achieve this:

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

if(ant.doDeleteFile == 'y') {
    // Call copy task
}

Note that unlike System.console() this also works with the Gradle Daemon (tested on Linux).

like image 120
Benjamin Muschko Avatar answered Nov 15 '22 09:11

Benjamin Muschko