Gradle Recurring Module Not Found / Could not find or load main class error in Java 9+

ジェナちゃん :

I'm running a JavaFX 11 (TornadoFX 2.0.0-RC1) application via gradle, but every time I use the run task I get either a "Could not find Module" or "Could not find or load main class" error.

When I run clean before the build, it works fine, but on subsequent builds, I get the error again until I run another clean. Having to run clean before every build is rather time-consuming, so I'm hoping there's a solution that removes the errors properly.

Console Output:

14:34:30: Executing task 'run'...


> Configure project :STTSim-TornadoFX
Found module name 'STTSim.TornadoFX'

> Task :STTSim-TornadoFX:compileKotlin
> Task :STTSim-TornadoFX:compileJava
> Task :STTSim-TornadoFX:processResources UP-TO-DATE
> Task :STTSim-TornadoFX:classes

> Task :STTSim-TornadoFX:run FAILED
WARNING: module-info.class ignored in patch: D:\OneDrive\Hot Storage\Coding\Java\Personal\STTSim\STTSim-TornadoFX\build\classes\kotlin\main
Error: Could not find or load main class com.genguava.sttsim.app.SimApp in module STTSim.TornadoFX

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':STTSim-TornadoFX:run'.
> Process 'command 'C:\Program Files\Java\jdk-11.0.1\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
4 actionable tasks: 3 executed, 1 up-to-date
Process 'command 'C:\Program Files\Java\jdk-11.0.1\bin\java.exe'' finished with non-zero exit value 1
14:34:33: Task execution finished 'run'.

Application build.gradle.kts:

val tornadoFXVersion: String by project

plugins {
    application
    id("org.openjfx.javafxplugin") version "0.0.7"
}

repositories {

}

dependencies {
    implementation("no.tornado:tornadofx:$tornadoFXVersion")
    implementation("com.google.code.gson:gson:2.8.5")
    implementation("org.hildan.fxgson:fx-gson:3.1.2")
    implementation("org.jsoup:jsoup:1.11.3")
}

application {
    mainClassName = "STTSim.TornadoFX/com.genguava.sttsim.app.SimApp"
    applicationDefaultJvmArgs = listOf(
            "--add-opens=javafx.controls/javafx.scene.control=tornadofx",
            "--add-opens=javafx.controls/javafx.scene.control.skin=tornadofx",
            "--add-opens=javafx.graphics/javafx.scene=tornadofx"
    )
}

javafx {
    modules = listOf("javafx.controls", "javafx.media", "javafx.web", "javafx.swing", "javafx.fxml")
    version = "11.0.1"
}

/*
tasks.withType(JavaCompile::class) {
    options.compilerArgs.add("--add-modules=java.sql")
}
*/

tasks.jar {
    manifest {
        attributes(mapOf("Class-Path" to configurations.runtimeClasspath.map { it.asPath }, "Main-Class" to application.mainClassName))
    }
    from(configurations.compile.map { entry -> zipTree(entry) }) {
        exclude("META-INF/MANIFEST.MF")
        exclude("META-INF/*.SF")
        exclude("META-INF/*.DSA")
        exclude("META-INF/*.RSA")
    }
}

sourceSets {
    main {
        output.setResourcesDir(File("build/classes/kotlin/main")) // dodgy workaround
    }
}

Root Project build.gradle.kts:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    java
}

buildscript {
    val kotlinVersion: String by project
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
        classpath("org.junit.platform:junit-platform-gradle-plugin:1.1.0")
    }
}

allprojects {
    val junitVersion: String by project

    repositories {
        mavenLocal()
        mavenCentral()
    }

    apply(plugin = "kotlin")
    apply(plugin = "org.junit.platform.gradle.plugin")

    dependencies {
        implementation(kotlin("stdlib"))
        testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
        testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
    }

    tasks.named<KotlinCompile>("compileKotlin") {
        kotlinOptions.jvmTarget = "1.8"
    }
}
Martin Zeitler :

it seems that module-info.class is not being applied, which may lead to the lack of definition, what the mainClassName is. making this module build might be the precondition to make the project build.

mainClassName = "STTSim.TornadoFX/com.genguava.sttsim.app.SimApp" might be invalid.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=152619&siteId=1