I have a library project which provides shared functionality for other projects. The implementation is written in Kotlin. However, I've ensured that the public interface of the library does not use any classes provided by Kotlin.
If we add this library as a dependency to a Java-only project, it transitively pulls in kotlin-stdlib
and kotlin-runtime
. Classes from Kotlin-stdlib can now be potentially (but mistakenly) used in the Java-only consumer project.
Is there a way to prevent this type leakage? Some options that I can think of:
Mark
kotlin-stdlib-*
asprovided
in Maven: Will this cause any issues at runtime? (ClassNotFoundException
and such)Shade + relocate
kotlin-stdlib-*
and/orkotlin-runtime
: With shading, I foresee issues if we depend on multiple Kotlin library projects. Also, I'm not sure if this will actually hide the Kotlin types.
Note: The question Using a kotlin library in java code does not apply here (misleading title). I specifically avoid that scenario.