Gradle未使用System.in等待扫描仪

5anewei6  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(89)

我尝试用gradleKotlin8.2运行我的项目,而不是等待扫描仪上的用户输入,它只是给我这个错误“线程中的异常“main”java.util.NoSuchElementException:未找到行”
这是我main中的代码:

Scanner scanner = new Scanner(System.in);

System.out.println("What would you like to do?\n==========================\n0) Quit\n1) Show all Tree Species\n2) Show tree species of conservation status\n3)Show all locations\n4)Show locations with forest coverage and/or rainfall");
System.out.print("Choice (0-4): ");
String choice = scanner.nextLine();

System.out.println("You chose " + choice);

这是我的build.gradle.kts文件:

plugins {
    id("java")
    id("application")
}

application {
    mainClass.set("programming3.StartApplication")
}

group = ".programming3"
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()
}

我试着把它添加到我的build.gradle文件中,但它没有任何帮助

tasks {
    run {
        System.`in`
    }
}

我也在网上搜索了一下,所有的解决方案在我目前的gradle版本中似乎都无效。
我找到了解决方案,需要将其添加到build.gradle文件中,以解决同样的问题:

tasks.getByName("run", JavaExec::class) {
 standardInput = System.`in`
}
shyt4zoc

shyt4zoc1#

下面是我找到的添加到build.gradle文件中的解决方案

tasks.getByName("run", JavaExec::class) {
 standardInput = System.`in`
}

相关问题