openjfx / javafx-gradle-plugin

Gradle plugin that makes it easy to work with JavaFX 11+
https://openjfx.io/
BSD 3-Clause "New" or "Revised" License
354 stars 62 forks source link

Empty jars should not be put into the module-path #111

Closed RationalityFrontline closed 2 years ago

RationalityFrontline commented 3 years ago

With JavaFx 17 or greater, runing javafx applications via the binary distribution generated by gradlew install will fail with the following error message:

Error occurred during initialization of boot layer
java.lang.module.FindException: Two versions of module javafx.base found in D:\XXX\build\install\XXX\lib (javafx-base-17.jar and javafx-base-17-win.jar)

This is because commit https://github.com/openjdk/jfx/commit/02b078a8a00803e03f4d2b5f06552f88dd0d5c00 removed the Automatic-Module-Name of the empty jar, which made both jars recognized as the same module.

The javafx-gradle-plugin should remove empty jars from the module path.

Sample project that can reproduce the issue: https://github.com/RationalityFrontline/jfx-test

RationalityFrontline commented 3 years ago

I made a temporary solution by reverting the Automatic-Module-Name:

Add the following content to your build.gradle.kts

afterEvaluate {
    configurations.runtimeClasspath.get().filter {
        it.name.startsWith("javafx") && it.name.endsWith("${javafx.version}.jar")
    }.files.forEach { jarFile ->
        val tmpDir = file("$buildDir/tmp/jfx_empty_jar")
        delete(tmpDir)
        tmpDir.resolve("META-INF/MANIFEST.MF").apply {
            ensureParentDirsCreated()
            val splits = jarFile.name.split('-')
            val moduleName = "${splits[0]}.${splits[1]}Empty"
            writeText(
                """
                    Manifest-Version: 1.0
                    Automatic-Module-Name: $moduleName

                """.trimIndent()
            )
        }
        zipTo(jarFile, tmpDir)
    }
}
Siedlerchr commented 3 years ago

There is a new released version for JavaFX which reverted that feature https://gluonhq.com/products/javafx/openjfx-17-release-notes/#17.0.0.1