13.1.3 Using Project Lombok

Project Lombok is a popular java library that adds a number of useful AST transformations to the Java language via annotation processors.

Since both Micronaut and Lombok use annotation processors, special care needs to be taken when configuring Lombok to ensure that the Lombok processor runs before Micronaut’s processor.

For example in Gradle adding the following dependencies to the dependencies block:

Configuring Lombok in Gradle

  1. compileOnly 'org.projectlombok:lombok:1.18.12'
  2. annotationProcessor "org.projectlombok:lombok:1.18.12"
  3. ...
  4. // Micronaut processor define after Lombok
  5. annotationProcessor "io.micronaut:micronaut-inject-java"

Or when using Maven:

Configuring Lombok in Maven

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.projectlombok</groupId>
  4. <artifactId>lombok</artifactId>
  5. <version>1.18.12</version>
  6. <scope>provided</scope>
  7. </dependency>
  8. </dependencies>
  9. ...
  10. <annotationProcessorPaths combine.self="override">
  11. <path>
  12. <!-- must precede micronaut-inject-java -->
  13. <groupId>org.projectlombok</groupId>
  14. <artifactId>lombok</artifactId>
  15. <version>1.18.12</version>
  16. </path>
  17. <path>
  18. <groupId>io.micronaut</groupId>
  19. <artifactId>micronaut-inject-java</artifactId>
  20. <version>${micronaut.version}</version>
  21. </path>
  22. <path>
  23. <groupId>io.micronaut</groupId>
  24. <artifactId>micronaut-validation</artifactId>
  25. <version>${micronaut.version}</version>
  26. </path>
  27. </annotationProcessorPaths>
In both cases (Gradle and Maven) the Micronaut processor should be configured after the Lombok processor, reversing the order of the declared dependencies will not work.