Gradle,Lombok和JPAMetalModel处理器:项目无法编译(包lombok不存在)

4

我在我的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。

另一个线程中,我找到了一个可能类似的错误,但是与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"]
1个回答

0

compileJava.options.compilerArgs += [ "-proc:only", ]

编译Java选项.编译器参数+=[ "-proc:only", ]

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接