AspectJ + Gradle + Lombok not working

There is a solution to this in ANT, but how to do it with gradle? Can this be done using postcompilation weaving? The point of compiling with Lombok to get all the generated delombok code and then weaving the aspect on that generated delombok code instead of drawing its aspect?

These SO posts below seem to have nothing convincing on how to fix this problem?

Lombok not working with AspectJ? Gradle + RoboBinding with AspectJ + Lombok incompatible together

DiscussionThread http://aspectj.2085585.n4.nabble.com/AspectJ-with-Lombok-td4651540.html

Thanks Setzer

+6
source share
1 answer

This question is actually quite old, but since I came across the same problem, I still want to share my solution.

The best solution I've found is this . In fact, there is no native AspectJ support in Gradle, and existing plugins (like the Gradle AspectJ plugin) do not work with Lombok. So the solution is to enable time-based compilation in your code manually. Ready to go gradle.build for Java 8 is

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 } } 

You can find an additional explanation in the article already mentioned above . The build.gradle given here is an updated version of the version given in the article to allow the use of Java 8 and AspectJ version 1.8.9, and in addition, all unnecessary things are deleted.

0
source

All Articles