Skip to content

Beans get duplicated with kapt and keepJavacAnnotationProcessors = true #7266

Open
@korri123

Description

@korri123

Expected Behavior

Java and Kotlin code should work in harmony, where only one bean (and one path mapping) per Java class gets generated. This bug happened when adding Kotlin code to an existing Micronaut Java app containing Java Micronaut Controllers.

keepJavacAnnotationProcessors in kapt is enabled so Lombok in Java still compiles.
If keepJavacAnnotationProcessors = true is emitted from build.gradle then everything works as expected.

Actual Behaviour

Duplicate beans and endpoints get instantiated so endpoint returns Bad Request as Micronaut doesn't know which endpoint to choose. Internally in Micronaut the classloader returns resources both from build/classes/java and build/tmp/kapt3/classes, which Micronaut creates beans from and therefore duplicate controllers.

Steps To Reproduce

  1. Clone https://github.com/korri123/MicronautErrorTest
  2. Run the test file named src/test/kotlin/com/example/DemoTest.kt which should succeed as it asserts the error message happens.

Environment Information

  • Ubuntu 20.4
  • JDK 17

Example Application

https://github.com/korri123/MicronautErrorTest

Version

3.4.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions