Document how to use Lombok with Micronaut

See original GitHub issue

I tried to use Micronaut with Lombok and there seems to be some kind of conflict between the annotation processing and compile-time tasks that Micronaut executes to process DI and the class metadata, and the annotation processing that Lombok does.

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. Create a simple micronaut project with gradle-lombok plugin
  2. Create a Controller (or any other DI enabled class)
  3. Create a simple Dto with @Data or other annotation from Lombok
  4. Call one of the generated methods of the Dto from inside the Controller

An important point to highlight is that if I don’t use annotations on the Controller, the build is successful (as it doesn’t generate all the metadata classes).

Expected Behaviour

Compile successful

Actual Behaviour

Compile error: symbol not found

Environment Information

  • Operating System: Mac/bash
  • Micronaut Version: 1.0.0-SNAPSHOT
  • JDK Version: 1.8.0_121

Example Application

build.gradle

plugins {
    id 'io.franzbecker.gradle-lombok' version '1.14'
    id 'java'
}

GreetingDto.java

@Data
public class GreetingDto {
    private String greeting;
}

GreetingController.java

@Controller("/hello-world")
public class GreetingController {
    @Get
    public GreetingDto login(){
        GreetingDto dto = new GreetingDto();
        dto.setGreeting("Hello world!");
        return dto;
    }
}

Console output

> Task :compileJava FAILED
Note: Creating bean classes for 1 type elements
/Users/sebastian/development/hello-world/src/main/java/controller/GreetingController.java:17: error: cannot find symbol
        dto.setGreeting("Hello world!");
           ^
  symbol:   method setGreeting(String)
  location: variable dto of type GreetingDto
1 error

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

21reactions
rubensyltekcommented, Jun 15, 2018

In maven, I had to add lombok processor to pom file explicitly and before micronaut processor

<annotationProcessorPaths>
  <path>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.0</version>
  </path>
  <path>
    <groupId>io.micronaut</groupId>
    <artifactId>inject-java</artifactId>
    <version>${micronaut.version}</version>
  </path>
</annotationProcessorPaths>
4reactions
graemerochercommented, May 28, 2018

Seems if you define:

    compileOnly 'org.projectlombok:lombok:1.16.20'
    annotationProcessor "org.projectlombok:lombok:1.16.20"

Before

annotationProcessor "io.micronaut:inject-java"

Your example compiles. This does however seem fragile to me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Management & Monitoring - Micronaut Documentation
Micronaut is a modern, JVM-based, full stack Java framework designed for building modular, easily testable JVM applications with support for Java, Kotlin, and ......
Read more >
java - Why lombok, micronaut and querydsl does not work with ...
I have this error with @Slfj java: cannot find symbol symbol: variable log. Why lombok, micronaut and querydsl does not work with micronaut...
Read more >
13.1.3 Using Project Lombok - 《Micronaut v2.3.1 ... - 书栈网
13.1.3 Using Project Lombok Micronaut is a modern, JVM-based, full stack Java framework designed for building modular, easily testable JVM ...
Read more >
Micronaut Data - GitHub Pages
If you intend to use Lombok with Micronaut Data then you must place the Lombok annotation processor before the Micronaut processors in your...
Read more >
Micronaut | IntelliJ IDEA Documentation - JetBrains
Create a new Micronaut project · Launch IntelliJ IDEA. If the Welcome screen opens, click New Project. Otherwise, from the main menu, select ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found