What if you can't use readLine properly in Gradle/IDEA
This article mainly explains "What to do if you can't use readLine normally in Gradle/IDEA". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "What to do if readLine cannot be used normally in Gradle/IDEA"!
problem
In console programs built by Gradle, the standard input readLine always returns null
reason
Gradle's standard inputs are not bound to system standard inputs by default and need to be set manually
solution
Add to build.gradle.kts
tasks.named("run") { standardInput = System.` in`}
If you need cleaner output, you can use
gradle console:run -q --console=plain
Solution (Groovy)
Add to build.gradle
run { standardInput = System.in}
Supplement: Handling issues where jline does not work properly in the IDEA development environment
Phenomenon: When developing an application in IDEA and using jline to capture console input, it cannot run normally, mainly reflected in the following code that cannot be executed after entering carriage return:
ConsoleReader reader = new ConsoleReader();
reader.readLine("> ");
Solutions:
Before using jline, execute the following code:
jline.TerminalFactory.registerFlavor(TerminalFactory.Flavor.WINDOWS, jline.UnsupportedTerminal.class);
You can also add parameters to the program startup command line
-Djline.terminal=jline.UnsupportedTerminal
At this point, I believe that everyone has a deeper understanding of "how to use readLine normally in Gradle/IDEA", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!