Using lombok with gradle and spring-boot

With the latest Lombok 1.18 it’s simple. io.franzbecker.gradle-lombok plugin is not required. Example dependencies from my project:

dependencies {
    implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
    implementation "org.springframework.social:spring-social-facebook"
    implementation "org.springframework.social:spring-social-twitter"
    implementation "org.springframework.boot:spring-boot-starter-data-jpa"

    testImplementation "org.springframework.boot:spring-boot-starter-test"

    runtimeClasspath "org.springframework.boot:spring-boot-devtools"
    runtime "mysql:mysql-connector-java"

    // https://projectlombok.org
    compileOnly 'org.projectlombok:lombok:1.18.20'
    annotationProcessor 'org.projectlombok:lombok:1.18.20'
}

Other suggestions:

  1. testCompile("junit:junit") is not required because the spring-boot-starter-test “Starter” contains JUnit.

  2. Use implementation or api configuration instead of compile (since Gradle 3.4). How do I choose the right one?

  3. Do not use compile configuration for devtools. A tip from Developer Tools guide:

    Flagging the dependency as optional in Maven or using a custom developmentOnly configuration in Gradle (as shown above) is a best practice that prevents devtools from being transitively applied to other modules that use your project.

  4. If you use IntelliJ IDEA, make sure you have Lombok plugin installed and Annotation Processing enabled. To make an initial project setup easier for newcomers you can also specify the Lombok plugin as required.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)