title: How to start an interactive java app with gradle
body: <p>I want to write a gradle task that runs me this small application:</p>
  
  <pre><code>import java.lang.IllegalArgumentException
  
  class TestApp{
      companion object {
          @JvmStatic
          fun main(args:Array&lt;String&gt;){
              val a = try{
                  args[0].toInt()
              }catch (e:Exception) {throw argException}
  
              val b = try{
                  args[1].toInt()
              }catch (e:Exception) {throw argException}
  
              print("$a + $b = ")
              val answer = readLine()!!.toInt()
  
              println(if(a+b == answer)"CORRECT" else "WRONG!")
          }
  
          private val argException:IllegalArgumentException by lazy { IllegalArgumentException("expecting two integers as args") }
      }
  }
  </code></pre>
  
  <p>If I run the application with, say, Intellij, the app will pause at the <code>readline()</code> and expect user input.</p>
  
  <p>However, if I add a gradle task for it</p>
  
  <pre><code>task runTestApp(type:JavaExec){
      main = "${javaMainTestApp}"
      classpath = sourceSets.main.runtimeClasspath
  }
  </code></pre>
  
  <p>and run, say, </p>
  
  <pre><code>gradle runTestApp --args="2 4"
  </code></pre>
  
  <p>Then I get</p>
  
  <pre><code>2 + 4 = Exception in thread "main" kotlin.KotlinNullPointerException
          at [...].app.TestApp$Companion.main(TestApp.kt:19)
          at [...].app.TestApp.main(TestApp.kt)
  
  </code></pre>
  
  <p>Why is that? And more importantly, how do I get the execution to wait for user input?</p>
  
  <p><strong><em>UPDATE</em></strong></p>
  
  <p>Thanks @tim_yates:</p>
  
  <p>adding <code>standardInput = System.in</code> makes the app accept user input</p>
  
  <p>but results in an output like:</p>
  
  <pre><code>3 + 5 =
  &lt;&lt;==========---&gt; 80% EXECUTING [20s]
  &gt; :runTestApp
  8
  </code></pre>
  
  <p>where 8 is the user input.</p>
  
  <p>consequently, when the app finishes, the output reads</p>
  
  <pre><code>3 + 5 =
  &lt;&lt;======CORRECT&gt; 80% EXECUTING [22s]
  </code></pre>