我在我的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启动应用程序工作正常;只有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"]
答案 0 :(得分:0)
compileJava.options.compilerArgs + = [ “ -proc:only”, ]