acmoune
acmoune

Reputation: 3433

How to add Lombok to a Gradle Java Library project?

I tried this:

plugins {
  // Apply the java-library plugin to add support for Java Library
  id 'java-library'
  id 'io.freefair.lombok' version '3.8.4'
}

But I'm getting this error:

Unable to load class 'org.gradle.api.plugins.quality.FindBugsPlugin'.
This is an unexpected error. Please file a bug containing the idea.log file.

Upvotes: 2

Views: 13496

Answers (1)

WBLord
WBLord

Reputation: 1025

Lombok is available in maven central, so telling Gradle to download lombok is easy.

The Lombok Gradle Plugin There is a plugin for gradle that we recommend you use; it makes deployment a breeze, and makes it easy to do additional tasks, such as delomboking. The plugin is open source. Read more about the gradle-lombok plugin.

Gradle without a plugin If you don't want to use the plugin, gradle has the built-in compileOnly scope, which can be used to tell gradle to add lombok only during compilation. Your build.gradle will look like:

repositories {
    mavenCentral()
}

dependencies {
    compileOnly 'org.projectlombok:lombok:1.18.16'
    annotationProcessor 'org.projectlombok:lombok:1.18.16'
    
    testCompileOnly 'org.projectlombok:lombok:1.18.16'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
}

Remember that you still have to download lombok.jar (or find it in gradle's caches) and run it as a jarfile, if you wish to program in eclipse. The plugin makes that part easier.

Official site lombok -> https://projectlombok.org/setup/gradle

Upvotes: 8

Related Questions