I have the following data class
in my Kotlin code that uses Quarkus as a server side framework.
data class Location(
val id: String,
val serviceTimeInMinutes: Long,
val openingTimes: List<OpeningTime>,
) {
val sortedOpeningTimes: List<OpeningTime> by lazy {
openingTimes.sortedWith { o1, o2 ->
if (o1.weekday == o2.weekday) {
o1.from.compareTo(o2.from)
} else {
o1.weekday.compareTo(o2.weekday)
}
}
}
}
When I now run ./gradlew quarkusDev
, I get the following warning:
2023-08-22 15:13:28,401 WARN [io.qua.dep.ste.ReflectiveHierarchyStep] (build-4) Unable to properly register the hierarchy of the following classes for reflection as they are not in the Jandex index:
- kotlin.Lazy (source: <unknown>)
- kotlin.jvm.functions.Function1 (source: <unknown>)
Consider adding them to the index either by creating a Jandex index for your dependency via the Maven plugin, an empty META-INF/beans.xml or quarkus.index-dependency properties.
When I change the property to an ordinary property by removing the by lazy
-block, the line with the kotlin.Lazy
disappears as expected.
However, if I wanted to lazily execute that block, is there a way to get rid of that warning? And is there a way to get rid of the warning for kotlin.jvm.functions.Function1
?
I am aware of the configuration properties quarkus.index-dependency.<...>
, which I already used to get rid of that warning for the threeten library like this:
quarkus.index-dependency.threeten.group-id=org.threeten
quarkus.index-dependency.threeten.artifact-id=threeten-extra
I suppose if I knew group-id
and artifact-id
of Kotlin (if they exist), adding extra lines in the application.properties
might be worth a try.
Just stumbled upon the solution myself: Lazy
and Function1
both are implemented in the kotlin stdlib.
Adding the stdlib to the Quarkus index dependencies with
quarkus.index-dependency.kotlin.group-id=org.jetbrains.kotlin
quarkus.index-dependency.kotlin.artifact-id=kotlin-stdlib
is sufficient to remove the warning.
Probably it would be a nice feature for the Quarkus Kotlin extension to allow devs omitting that additional configuration - so I think I'll raise an issue there I've raised this issue on GitHub.