1

I've been smashing my head against the wall all night. So I have a build.gradle.kts:

plugins {
    // Apply the java plugin to add support for Java
    java

    // Apply the application plugin to add support for building a CLI application.
    application
}

repositories {
    // Use jcenter for resolving dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

dependencies {
    // This dependency is used by the application.
    implementation("com.google.guava:guava:28.2-jre")

    // Use JUnit test framework
    testImplementation("junit:junit:4.12")

    // Use Google Protocol Buffers
    implementation("com.google.protobuf:protobuf-java:3.11.0")
}

application {
    // Define the main class for the application.
    mainClassName = "carnival.EntryPoint"
}

When I try to get user input from the terminal with new Scanner(System.in), I'm given this:

> Task :run FAILED
Exception in thread "main" java.util.NoSuchElementException
        at java.base/java.util.Scanner.throwFor(Scanner.java:937)
        at java.base/java.util.Scanner.next(Scanner.java:1478)
        at carnival.App.run(App.java:56)
        at carnival.EntryPoint.main(EntryPoint.java:9)

FAILURE: Build failed with an exception.

So I try to make my own run task:

/// ...
// removed application plugin

sourceSets {
    main {
        java.srcDir("src/main/java")
    }
}

tasks.register<JavaExec>("run") {
    main = "carnival.EntryPoint"
    standardInput = System.`in`
}

But apparently I'm not setting the source directory correctly because I get the following:

Error: Could not find or load main class carnival.EntryPoint
Caused by: java.lang.ClassNotFoundException: carnival.EntryPoint

Any help would be greatly appreciated.

Alek Sung
  • 51
  • 7
  • Your issue is potentially not related to Gradle at all. Did you check [java.util.NoSuchElementException - Scanner reading user input](https://stackoverflow.com/q/13042008/5006866)? – thokuest Jun 09 '20 at 06:38
  • Yeah I saw this and I'm creating a Scanner basically from the start of the application without closing any previous Scanners. – Alek Sung Jun 09 '20 at 13:26
  • consider posting relavant application code where this issue occurs. – thokuest Jun 09 '20 at 18:25

0 Answers0