如何将 Lombok 添加到 Gradle Java 库项目?

How to add Lombok to a Gradle Java Library project?

我试过这个:

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

但是我收到这个错误:

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

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.

lombok 官方网站 -> https://projectlombok.org/setup/gradle