According to its documentation ,
A minimal build.gradle looks like this:
plugins { id 'io.franzbecker.gradle-lombok' version '1.10' id 'java' } repositories { jcenter() // or Maven central, required for Lombok dependency }
After applying the plugin, the Lombok annotations can be used directly in any Java code
This is my build.gradle
group 'tests'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'io.franzbecker.gradle-lombok'
plugins {
id 'io.franzbecker.gradle-lombok' version '1.10'
id 'java'
}
lombok {
version = "1.16.4"
sha256 = "3ca225ce3917eac8bf4b7d2186845df4e70dcdede356dca8537b6d78a535c91e"
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter() // https://stackoverflow.com/questions/41319176/how-to-make-gradle-add-lombok-to-its-project-and-external-dependencies-libraries
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
When I run gradle build
, it gives me
classpath
No dependencies
BUILD SUCCESSFUL
But the Lombok annotations are not available. I've also tried adding compileOnly 'org.projectlombok:lombok:1.16.18'
under dependencies
, with the same result. I understand that the plugin should have been applied. I'm using Intellij, but I don't think this has anything to do with the IDE, since the problem is not that the annotations are not recognized, but that they're not even available.
What am I missing?
Try the following in your build.gradle
apply plugin: 'java'
group = 'com.example'
version = '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.4'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
Note that I'm using IntelliJ 2018.2 and have enabled annotations under Preferences | Build, Execution, Deployment | Compiler | Annotation Processors
Preferences | Build, Execution, Deployment | Compiler | Annotation Processors
Preferences | Build, Execution, Deployment | Compiler | Annotation Processors
. If that does not work, then run ./gradlew clean build
from the command prompt and see if there's a build error.
If you don't see any errors then lombok can be used as follows
package com.example.java8;
import lombok.Data;
@Data
public class Country {
private final String country_iso_code;
private final String name;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.