2

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"
    }
}
  • 1
    Possible duplicate of [Gradle - Could not find or load main class](https://stackoverflow.com/questions/24924932/gradle-could-not-find-or-load-main-class) – Martin Zeitler Feb 03 '19 at 13:58
  • I've read that one, however, this appears to be an issue with modules and specifically Kotlin only projects (if my gut doesn't lie to me). None of the things mentioned in that question apply here. – ジェナちゃん Feb 03 '19 at 14:04
  • 1
    `Error: Could not find or load main class` is rather explicit ...there is no entry point. just unsure in how far the preceeding `WARNING: module-info.class ignored in patch` is related to that. – Martin Zeitler Feb 03 '19 at 14:12
  • Yes, but the main file is there and when using clean it works perfectly (unlike the other one). There's also the message `WARNING: module-info.class ignored in patch: D:\OneDrive\Hot Storage\Coding\Java\Personal\STTSim\STTSim-TornadoFX\build\classes\kotlin\main` which points towards this being an issue with incremental builds and Kotlin only code, rather than a mistake in my code (like the referenced question was). – ジェナちゃん Feb 03 '19 at 14:14
  • 1
    the root project is uses the `java` plugin. try `./gradlew STTSim.TornadoFX:dependencies` once. 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. or the `srcSet` might not have `kotlin` directory added. – Martin Zeitler Feb 03 '19 at 14:18
  • That worked, thank you so much! Can you post that as an answer so I can mark it correct, or should I just answer it myself? – ジェナちゃん Feb 03 '19 at 14:23

1 Answers1

2

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.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216