In my app, I have some code that needs data from command line, such as:
def input= new DataInputStream(System.in)When I applied the method I learned from mrhaki's post, I could run my app, but have no chance to input some data from command line. The app exited with an exception because it did not pause and got null from command line! After digging the gradle api doc, I found I could set the value of standardInput property of JavaExec task. So I made some change to my build.gradle:
println "Work Dir:"
def rootDir= input.readLine()
println "Test Plan:"
def testplan= input.readLine()
task (processplan, dependsOn: classes, type: JavaExec) {Note that the last line. I set the value of standardInput to "System.in". Then I ran the build task again. This time, the app stopped to wait for user's inputting. And app worked fine!
main= '....'
classpath= sourceSets.main.runtimeClasspath
standardInput= System.in
}
So, If your app needs user to input some data from command line, you'd better set the value of standardInput. Hope this tip is help for you.