Before selecting a Gradle task, select a user

I will switch our application to deploy Capistrano to Gradle.

Here you need to make an interactive user script.

I am stuck to provide user input between tasks.

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 looking for a solution to this problem. If you know about this method than please let me know.

Thanks in advance.

+4
source share
2 answers

Have you tried using the console? Something like that:

 if (System.console().readLine().toLowerCase() == 'y') ... 
+1
source

Gradle allows you to use existing Ant tasks inside your build script. To achieve this, you can use the [Ant] [1] input task:

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

+11
source

Source: https://habr.com/ru/post/1383434/


All Articles