13.3.4 Kotlin and Retaining Parameter Names

Like with Java, the parameter name data for method parameters is not retained at compile time when using Kotlin. This can be a problem for Micronaut if you do not define parameter names explicitly and depend on an external JAR that is already compiled.

To enable retention of parameter name data with Kotlin, set the javaParameters option to true in your build.gradle:

configuration in Gradle

  1. compileTestKotlin {
  2. kotlinOptions {
  3. jvmTarget = '1.8'
  4. javaParameters = true
  5. }
  6. }

Or if using Maven configure the Micronaut Maven Plugin accordingly:

configuration in Maven

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <!-- ... -->
  4. <build>
  5. <plugins>
  6. <!-- ... -->
  7. <plugin>
  8. <artifactId>kotlin-maven-plugin</artifactId>
  9. <groupId>org.jetbrains.kotlin</groupId>
  10. <configuration>
  11. <javaParameters>true</javaParameters>
  12. <!-- ... -->
  13. </configuration>
  14. <!-- ... -->
  15. </plugin>
  16. <!-- ... -->
  17. </plugins>
  18. </build>
  19. </project>