0

When i run the code inside IntelliJ IDEA it works perfectly but if i try running it from terminal with "gradlew run" it prints the question but doesn't give me the chance to type anything. It immediately prints "Hello null by Gradle" and finishes the run. Does anyone know why it does like this?

public static void main(String[] args) throws IOException {
    System.out.println("What's your name?");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String name = br.readLine();
    System.out.println("Hello " + name + " By Gradle");
    br.close();
}

I create this project with the task "gradle init" i chose application, Java, Groovy, JUnit Juppiter.

1 Answers1

0

Two actions can help you to get this resolved;

  1. Add below task in your build.gradle.
run{
    standardInput = System.in
}
  1. Though this enables your command-line to accept input now. It still provides some ambiguity in run and hence executing below command can help you to get your exact expected output.

gradle --console=plain run

Detailed explanation wonderfully explained in console-application-with-java-and-gradle

Saiprasad Bane
  • 477
  • 4
  • 9