Search code examples
gradlekotlinjavafxtornadofx

JavaFX module does not export to unnamed module


I am building a JavaFX application using gradle (with Kotlin and TornadoFX). Building and running it works fine with the below gradle build and IntelliJ but using the application plugin, and running the application, I get the following error:

Caused by: java.lang.IllegalAccessError: superinterface check failed: class de.codecentric.centerdevice.javafxsvg.SvgImageLoaderFactory (in
 unnamed module @0x591c2277) cannot access class com.sun.javafx.iio.ImageLoaderFactory (in module javafx.graphics) because module javafx.gr
aphics does not export com.sun.javafx.iio to unnamed module @0x591c2277

Below is my gradle build script. How can I solve this.

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.3.50'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

application {
    mainClassName = 'MainKt'
}

javafx {
    version = "13"
    modules = ['javafx.controls', 'javafx.base', 'javafx.graphics']
}

repositories {
    mavenCentral()
    mavenLocal()
    jcenter()
    maven {
        url "https://plugins.gradle.org/m2/"
    }
    maven {
        url "http://4thline.org/m2"
    }
}

dependencies {
    ...
}

tasks.test {
    useJUnitPlatform()
    testLogging {
        events("passed", "skipped", "failed")
    }
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

Solution

  • Since I was working with a non-module project and was relying on JavaFX's modules, that is what caused the errors when I executed

    > gradle run
    

    I appended the following to my gradle file:

    run {
        applicationDefaultJvmArgs = ['--add-exports=javafx.graphics/com.sun.javafx.iio=ALL-UNNAMED',
                                     '--add-exports=javafx.graphics/com.sun.javafx.iio.common=ALL-UNNAMED',
                                     '--add-exports=javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED',
                                     '--add-exports=javafx.graphics/com.sun.glass.ui=ALL-UNNAMED',
        ]
    
        jvmArgs = ['--add-exports=javafx.graphics/com.sun.javafx.iio=ALL-UNNAMED',
                   '--add-exports=javafx.graphics/com.sun.javafx.iio.common=ALL-UNNAMED',
                   '--add-exports=javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED',
                   '--add-exports=javafx.graphics/com.sun.glass.ui=ALL-UNNAMED',
        ]
    }
    

    The reason the "applicationDefaultJvmArgs" is there is due to the fact that the application gradle plugin uses that to configure jvm arguments instead of "jvmArgs".