1

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"
}
SyncReactor
  • 61
  • 1
  • 5
  • Have you tried adding an export of the package into the unnamed module? An example can be found here: https://stackoverflow.com/questions/58082298/gradle-run-with-add-exports – Jochen Reinhardt Jan 07 '20 at 09:06
  • Thanks for your response. That question did help. The issue I was having through is that the application plugin requires "applicationDefaultJvmArgs", not "jvmArgs". But yes, to anyone that needs help in the future, add the --add-exports for any packages that return that error. – SyncReactor Jan 08 '20 at 04:48

1 Answers1

5

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".

SyncReactor
  • 61
  • 1
  • 5