I'm trying to run my project with gradle Kotlin 8.2 and instead of waiting for a user input on scanner it simply gives me this error "Exception in thread "main" java.util.NoSuchElementException: No line found"
This is the code in my main:
Scanner scanner = new Scanner(System.in);
System.out.println("What would you like to do?\n==========================\n0) Quit\n1) Show all class1\n2) Show specific class1\n3)Show all class2\n4)Show specific class2");
System.out.print("Choice (0-4): ");
String choice = scanner.nextLine();
System.out.println("You chose " + choice);
And this is my build.gradle.kts file:
plugins {
id("java")
id("application")
}
application {
mainClass.set("program.StartApplication")
}
group = ".program"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
implementation("com.google.code.gson:gson:2.10.1")
}
tasks.test {
useJUnitPlatform()
}
I tried adding this to my build.gradle file but it did nothing to help
tasks {
run {
System.`in`
}
}
I also searched online and all solutions seem to not be valid in my current version of gradle.
I found the solution, need to add this into the build.gradle file for those having the same issue:
tasks.getByName("run", JavaExec::class) {
standardInput = System.`in`
}
Here is the solution I found to add to the build.gradle file
tasks.getByName("run", JavaExec::class) {
standardInput = System.`in`
}