Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically add Kotlin stdlib as an index dependency when using quarkus-kotlin extension #35504

Closed
greyhairredbear opened this issue Aug 23, 2023 · 14 comments · Fixed by #35708
Labels
area/kotlin kind/enhancement New feature or request triage/needs-feedback We are waiting for feedback.
Milestone

Comments

@greyhairredbear
Copy link

greyhairredbear commented Aug 23, 2023

Description

As already discussed in this stackoverflow-post:

When using Quarkus 3.1.3.Final, the quarkus-kotlin extension and Gradle, the Kotlin stdlib (containing classes like e.g. Lazy or Function1) is not on the Jandex index. This leads to the following warning on startup, if any of these classes are used:

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.

Adding

quarkus.index-dependency.kotlin.group-id=org.jetbrains.kotlin
quarkus.index-dependency.kotlin.artifact-id=kotlin-stdlib

to the application.properties file fixes that warning.

It would be nice to have the stdlib automatically added to the Jandex index when using the quarkus-kotlin extension to avoid that warning and to have to manually add what I would consider boilerplate to the application.properties file

@greyhairredbear greyhairredbear added the kind/enhancement New feature or request label Aug 23, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Aug 23, 2023

/cc @evanchooly (kotlin), @geoand (kotlin)

@geoand
Copy link
Contributor

geoand commented Aug 23, 2023

What is the warning you are seeing?

@geoand geoand added the triage/needs-feedback We are waiting for feedback. label Aug 23, 2023
@greyhairredbear
Copy link
Author

@geoand Sorry, added some information from the referenced post to this issue. Should be understandable without having to view the post now.

@geoand
Copy link
Contributor

geoand commented Aug 23, 2023

No problem. Any chance you can give the full watning message?

@greyhairredbear
Copy link
Author

Sorry, missed the Consider [...] part of the warning. Added it to the original post. If you're interested in the whole output of the startup:

17:35:20: Executing 'quarkusDev'...

> Task :processResources UP-TO-DATE
> Task :quarkusGenerateCode UP-TO-DATE
> Task :quarkusGenerateCodeDev
> Task :compileKotlin UP-TO-DATE
> Task :compileJava NO-SOURCE
> Task :classes UP-TO-DATE
> Task :processTestResources UP-TO-DATE
> Task :compileQuarkus-test-generated-sourcesKotlin NO-SOURCE
> Task :compileQuarkusTestGeneratedSourcesJava NO-SOURCE
> Task :quarkusGenerateCodeTests
> Task :compileTestKotlin UP-TO-DATE
> Task :compileTestJava NO-SOURCE
> Task :testClasses UP-TO-DATE

> Task :quarkusDev
Listening for transport dt_socket at address: 5005
Press [h] for more options>
Tests paused
Press [r] to resume testing, [h] for more options>
Press [r] to resume testing, [o] Toggle test output, [h] for more options>
Press [r] to resume testing, [o] Toggle test output, [h] for more options>
2023-08-23 17:35:23,305 INFO  [io.qua.ama.lam.run.MockEventServer] (build-32) Mock Lambda Event Server Started
2023-08-23 17:35:23,690 WARN  [io.qua.dep.ste.ReflectiveHierarchyStep] (build-18) 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.
__  ____  __  _____   ___  __ ____  ______ 
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ 
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \   
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/   
2023-08-23 17:35:24,626 INFO  [io.quarkus] (Quarkus Main Thread) optavrp 1.0.0-SNAPSHOT on JVM (powered by Quarkus 3.1.3.Final) started in 1.774s. Listening on: http://localhost:8080
2023-08-23 17:35:24,626 INFO  [io.qua.ama.lam.run.AbstractLambdaPollLoop] (Lambda Thread (DEVELOPMENT)) Listening on: http://localhost:8081/_lambda_/2018-06-01/runtime/invocation/next
2023-08-23 17:35:24,627 INFO  [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2023-08-23 17:35:24,627 INFO  [io.quarkus] (Quarkus Main Thread) Installed features: [amazon-lambda, cdi, kotlin, optaplanner, resteasy-reactive, resteasy-reactive-jackson, smallrye-context-propagation, vertx, webjars-locator]

@geoand
Copy link
Contributor

geoand commented Aug 24, 2023

Hm interesting.

Can you attach a small sample applicaiton that leads to this behavior? I want to see what causes these types to be including in the attempted reflection registration.

@gsmet
Copy link
Member

gsmet commented Aug 24, 2023

If in the end we have to add elements to the index, maybe we should add only the classes that make sense instead of the whole lib (if they are easy to determine).

@geoand
Copy link
Contributor

geoand commented Aug 24, 2023

My guess is that we should probably just exclude certain Kotlin classes from hierarchy traversal, but I want to see the sample first

@greyhairredbear
Copy link
Author

Hi, I've created a sample: https://github.com/greyhairredbear/quarkus-kotlin-stdlib-jandex-sample

Note: When creating the sample, I first tried to simply use a lazy-Block in a data class used by ExampleResource as an injected property. With this, I couldn't reproduce the warning. However, when using the data class within a @PlanningEntity from optaplanner (as I did in the project where the warning first occurred), the warning pops up.

So it seems to me that Lazy is kind of transitively included for reflection registration by optaplanner (if that makes sense?)

@geoand
Copy link
Contributor

geoand commented Aug 25, 2023

Hm... the sample doesn't trigger the warning for me so it would be great if you could add a clas that triggers it

@greyhairredbear
Copy link
Author

greyhairredbear commented Aug 25, 2023

Oh, sorry, seems like something in my git was off (maybe unstaged changes?) - I have the sample on my home laptop, so I'll update the project as soon as I get home

@geoand edit/update: I've added the missing changes to the repo, sorry again for messing up

@geoand
Copy link
Contributor

geoand commented Sep 4, 2023

Unless I am doing something wrong, I don't see any change

@greyhairredbear
Copy link
Author

Hmmm... That's very peculiar. I just ran ./gradlew quarkusDev on a clean checkout of the project and got the warning...

Screenshot 2023-09-04 at 10 56 01

On the main branch, ExampleResource.kt should look like this:

package com.example

import jakarta.enterprise.context.ApplicationScoped
import jakarta.ws.rs.GET
import jakarta.ws.rs.Path
import jakarta.ws.rs.Produces
import jakarta.ws.rs.core.MediaType
import org.optaplanner.core.api.domain.entity.PlanningEntity
import org.optaplanner.core.api.domain.solution.PlanningEntityCollectionProperty
import org.optaplanner.core.api.domain.solution.PlanningScore
import org.optaplanner.core.api.domain.solution.PlanningSolution
import org.optaplanner.core.api.domain.valuerange.ValueRangeProvider
import org.optaplanner.core.api.domain.variable.PlanningVariable
import org.optaplanner.core.api.score.buildin.hardmediumsoftlong.HardMediumSoftLongScore
import org.optaplanner.core.api.score.stream.Constraint
import org.optaplanner.core.api.score.stream.ConstraintFactory
import org.optaplanner.core.api.score.stream.ConstraintProvider

@PlanningSolution
class Solution {
  lateinit var id: String

  @ValueRangeProvider val planningValues: List<Int> = listOf(1, 2, 3)

  @PlanningEntityCollectionProperty //
  lateinit var entities: List<Entity>

  @PlanningScore var score: HardMediumSoftLongScore? = null

  constructor() // required for optaplanner

  constructor(id: String, entities: List<Entity>) {
    this.id = id
    this.entities = entities
  }
}

@PlanningEntity
class Entity {
  @PlanningVariable var planningVar: Int? = null

  /**
   * This triggers a warning
   */
  lateinit var t: Test

  constructor()

  constructor(t: Test) {
    this.t = t
  }
}

@ApplicationScoped
data class Test(val aString: String = "default") {
  val uppercase: String by lazy { aString.uppercase() }
}

class TestConstraintProvider : ConstraintProvider {
  override fun defineConstraints(constraintFactory: ConstraintFactory?): Array<Constraint> {
    return arrayOf()
  }
}

@Path("/hello")
class ExampleResource(
  /**
   * This doesn't trigger a warning
   */
  private val test: Test
) {

  @GET
  @Produces(MediaType.TEXT_PLAIN)
  fun hello(): String {
    val s = Solution("test", listOf(Entity(Test("aString"))))

    return test.uppercase
  }
}

@geoand
Copy link
Contributor

geoand commented Sep 4, 2023

Got it, thanks.

gsmet added a commit that referenced this issue Sep 5, 2023
Ignore reflection warnings for built-in Kotlin classes
@quarkus-bot quarkus-bot bot added this to the 3.4 - main milestone Sep 5, 2023
holly-cummins pushed a commit to holly-cummins/quarkus that referenced this issue Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kotlin kind/enhancement New feature or request triage/needs-feedback We are waiting for feedback.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants