实际上这个问题已经很老了,但是由于遇到了同样的问题,我还是想分享我的解决方案。
我找到的最佳解决方案是this。事实上,Gradle 中没有对 AspectJ 的内置支持,并且现有的插件(例如,Gradle AspectJ 插件)不适用于 Lombok。所以解决方案是在你的代码中手动启用编译时编织。为 Java 8 准备好的 gradle.build 是这样的
buildscript {
repositories {
jcenter()
maven { url 'http://repo.spring.io/plugins-release' }
}
dependencies {
}
}
apply plugin: 'idea' // if you use IntelliJ
apply plugin: 'java'
ext {
aspectjVersion = '1.8.9'
springVersion = '4.2.1.RELEASE'
}
repositories {
jcenter()
}
configurations {
ajc
aspects
compile {
extendsFrom aspects
}
}
dependencies {
compile "org.aspectj:aspectjrt:$aspectjVersion"
compile "org.aspectj:aspectjweaver:$aspectjVersion"
ajc "org.aspectj:aspectjtools:$aspectjVersion"
aspects "org.springframework:spring-aspects:$springVersion"
}
def aspectj = { destDir, aspectPath, inpath, classpath ->
ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties",
classpath: configurations.ajc.asPath)
ant.iajc(
maxmem: "1024m", fork: "true", Xlint: "ignore",
destDir: destDir,
aspectPath: aspectPath,
inpath: inpath,
classpath: classpath,
source: project.sourceCompatibility,
target: project.targetCompatibility
)
}
compileJava {
doLast {
aspectj project.sourceSets.main.output.classesDir.absolutePath,
configurations.aspects.asPath,
project.sourceSets.main.output.classesDir.absolutePath,
project.sourceSets.main.runtimeClasspath.asPath
}
}
compileTestJava {
dependsOn jar
doLast {
aspectj project.sourceSets.test.output.classesDir.absolutePath,
configurations.aspects.asPath + jar.archivePath,
project.sourceSets.test.output.classesDir.absolutePath,
project.sourceSets.test.runtimeClasspath.asPath
}
}
您可以在上面已经提到的文章中找到其他说明。这里给出的 build.gradle 是文章中给出的更新版本,以允许使用 Java 8 和 AspectJ 版本 1.8.9,此外还删除了所有不必要的东西。