Are Java Service Provider Interfaces supported in Kotlin?


I’ve created a Kotlin-Gradle project with four subprojects that implement the Java Service Provider Interface pattern, which I’ve used in Java. Unfortunately, the Kotlin version does not work… When I try to load the modules, none are located. Whereas, the “same” code in Java returns three providers, as expected. I am suspicious that Kotlin requires some additional tasks to compile or move things around, like when I tried to use Java 9 Modules in Kotlin. Anyway, I’d really appreciate any tidbits or examples… I need to implement a pluggable application, and would really like to use SPI. Here are links to my two experimental projects (Kotlin & Java):



Thank you for your time and interest!

Service providers are working fine in kotlin-jvm. The only important difference is file naming. You should remember that top level files in Kotlin are named MyClassKt instead of MyClass. This of course matters only if you need to reference a top-level function or property. Everything else should work fine.

Thank you for the quick information! I am happy to report that my Kotlin example is working. I will keep the link active in case it could help others. :slight_smile:

1 Like