Using sun.awt.image with Java 11

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?

1 Like

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

1 Like

After long investigations I found @file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") construction and it helps me. It’s strange anyway that Kotlin implement it’s own modules checking and don’t handle params such as --add-exports.