简体   繁体   English

未找到Gradle循环模块/在Java 9+中找不到或加载主类错误

[英]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. 我正在通过gradle运行JavaFX 11(TornadoFX 2.0.0-RC1)应用程序,但是每次使用运行任务时,都会收到“找不到模块”或“找不到或加载主类”错误。

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: 应用程序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: 根项目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"
    }
}

it seems that module-info.class is not being applied, which may lead to the lack of definition, what the mainClassName is. 似乎未应用module-info.class ,这可能导致缺少定义,即mainClassName是什么。 making this module build might be the precondition to make the project build. 进行此模块构建可能是进行项目构建的前提。

mainClassName = "STTSim.TornadoFX/com.genguava.sttsim.app.SimApp" might be invalid. mainClassName = "STTSim.TornadoFX/com.genguava.sttsim.app.SimApp"可能无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM