【发布时间】:2018-01-29 22:13:42
【问题描述】:
我在我的 gradle 项目中使用 lombok 并想创建一个 jar 文件,但每次我执行 jar 任务(无论是否在我的控制台或 eclipse ide 中触发)我都会收到我的 lombok 导入无法在这些类中找到的错误我在哪里使用 lombok 注释。示例输出:
... other lombok related error messages ...
/test/entity/geo/Region.java:11: error: package lombok does not exist
import lombok.EqualsAndHashCode;
^
/test/entity/geo/Region.java:12: error: package lombok does not exist
import lombok.NoArgsConstructor;
^
/test/entity/geo/Region.java:37: error: cannot find symbol
@Data
^
symbol: class Data
100 errors
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJpaModelgen'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
搜索了一段时间后,我发现有一个用于 gradle 和 lombok 的插件,但对于使用较新的 gradle 版本进行编译并不真正需要。我的 gradle 版本是 3.4.1 和 lombok 1.6.18。
在another thread 中,我发现可能有类似的错误,但使用 maven。 我想在我的 build.gradle 中尝试这个,但我不知道如何编写/定义这个......
使用我的 Eclipse ide 启动和运行我的 Spring Boot 应用程序可以正常工作;只有 gradle compileJava 任务在编译时似乎对 lombok 有问题。
这是我的 build.gradle:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:+") }
}
plugins {
id 'at.comm_unity.gradle.plugins.jpamodelgen' version '1.1.3'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'at.comm_unity.gradle.plugins.jpamodelgen'
apply plugin: 'war'
war {
baseName = 'test'
version = '0.0.1'
}
repositories { mavenCentral() }
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "org.springframework.boot:spring-boot-starter-data-rest"
compile("org.springframework.boot:spring-boot-devtools")
compile"org.springframework.boot:spring-boot-starter-test"
compile 'org.postgresql:postgresql:42.1.1'
compile 'javax.validation:validation-api:2.0.0.CR2'
compile 'org.hibernate:hibernate-java8:5.2.10.Final'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.8.9'
compileOnly('javax.servlet:jstl')
compile('org.apache.tomcat.embed:tomcat-embed-jasper')
compile('org.springframework.boot:spring-boot-starter-tomcat')
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.16.18'
compile "com.google.guava:guava"
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
sourceSets {
generated { java.srcDir "${buildDir}/generated/src/java/" }
}
ext['hibernate.version'] = '5.2.10.Final'
jpaModelgen {
library = "org.hibernate:hibernate-jpamodelgen:5.2.10.Final"
jpaModelgenSourcesDir = "src/generated/java"
}
compileJava.options.compilerArgs += ["-proc:none"]
【问题讨论】: