I need to use
sun.awt.image package in my Kotlin/JVM project and build it with Java 11. But I have an error:
Symbol is declared in module 'java.desktop' which does not export package 'sun.awt.image'. With Java I can use
--add-exports java.desktop/sun.awt.image=ALL-UNNAMED compiler param. Is there a similar option for the Kotlin compiler or other way to using this package?
I need to use
The problem is not Kotlin at all. The JDK 11 is deep into
java modules and
sun package must be loaded accordingly. Otherwise just ignore the modules stuff (like most of dev does on JVM) and import the jar from Mavan!
I made repository with two example projects (https://github.com/Feamor/KotlinJava11Test). The first is plain Java project with gradle. The second is Kotlin JVM project with gradle. All of them using
sun.awt.AppContext. When I use Java 11, first project buiding successfully due to
--add-exports param, added in
build.gradle file. But I can’t build Kotlin project. I need some solution.
Classes in a
sun. package are internal to that particular Java runtime. They’re not available on some JVMs, are not supported, may be changed or removed at any time, and shouldn’t be used.
It’s a good thing that Java 11 is now enforcing that; but it was wrong long before.
There are plenty of image-handling classes in the Java standard library, and in third-party libraries. I suggest using one of those, instead.