I have the following main Java class that I am trying to compile and run using the Gradle plugin in IntelliJ IDEA:
package com.mikidep.bookshop; import java.io.IOException; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); System.out.print("Inserisci testo qui: "); System.out.println(in.nextLine()); System.out.println("Yee!"); } }
My build.gradle follows:
group 'com.mikidep.bookshop' version '1.0-SNAPSHOT' apply plugin: 'application' mainClassName = "com.mikidep.bookshop.Main" sourceCompatibility = 1.5 repositories { mavenCentral() } dependencies { testCompile group: 'junit', name: 'junit', version: '4.11' } run { standardInput = System.in }
Now, if I run gradle run -q in the terminal, everything works as expected. However, there is such an IDEA startup configuration that I would like to use for testing:

Everything is fine until I make console input. in.nextLine() throws the following exception:
Exception in thread "main" java.util.NoSuchElementException: No line found on java.util.Scanner.nextLine (Scanner.java:1585) in com.mikidep.bookshop.Main.main (Main.java:10)
I also tried debugging it and noticed that all the fields in System.in seem to be nullified, for example, the whole thread was not initialized. Does anyone know what is going on?
EDIT: I just confirmed that this also affects the build script: I added these lines to the execution task
System.out.println("Wait...") System.in.read() System.out.println("Ok!")
But Gradle prints these two lines at once, without waiting for input.
source share