I am a new Kotlin programmer who has experience in Java; though, not with Gradle.
I created my project Shell/
using the Gradle Build Tool.
I ran the command gradle init --type kotlin-application
and created a new Kotlin Gradle project.
So, after creating the project via the Gradle Build Tool in my Terminal, I opened it up inside of Intellij.
Gradle had a boilerplate Hello World which I executed using ./gradlew build
and then ./gradlew run
inside of my Terminal; these commands worked fine, and I saw a "Hello World" output.
Then I changed the code up, and added this:
val PROMPT = ">>> "
while (true) {
print(PROMPT)
val userInput = readln()
println(userInput)
}
When I execute this code inside of Intellij, it works; however, when I run it inside of the Terminal with the same commands used earlier, I get:
Output for ./gradlew build
Path for java installation '/usr/lib/jvm/openjdk-11' (Common Linux Locations) does not contain a java executable
BUILD SUCCESSFUL in 668ms
7 actionable tasks: 7 up-to-date
Output for ./gradlew run
Path for java installation '/usr/lib/jvm/openjdk-11' (Common Linux Locations) does not contain
a java executable
> Task :app:run FAILED
>>> Exception in thread "main" kotlin.io.ReadAfterEOFException: EOF has already been reached
at kotlin.io.ConsoleKt.readln(Console.kt:152)
at pure.sass.AppKt.main(App.kt:9)
at pure.sass.AppKt.main(App.kt)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:run'.
> Process 'command '/usr/lib/jvm/java-11-openjdk-amd64/bin/java'' finished with non-zero exit value 1
My JAVA_HOME is set to usr/lib/jvm/java-11-openjdk-amd64/bin/java
My directory usr/lib/jvm/openjdk-11
only has a src.zip
file in it
The problem was with Gradle.
I use a Kotlin DSL, and I added this in my build.gradle.kts
:
tasks.named<JavaExec>("run") {
standardInput = System.`in`
}