There's a solution in ANT regarding this, but how do we accomplish this with gradle? Is it possible to do this via post-compilation weaving. Meaning compile with lombok to get all the generated delombok code, then have the aspect weave on this generated delombok code instead of aspectJ wiping it out?
These SO posts below don't seem to have anything conclusive about how to fix handle this?
Lombok does not work with AspectJ? Gradle + RoboBinding with AspectJ + Lombok are not compatible together
DiscussionThreadhttp://aspectj.2085585.n4.nabble.com/AspectJ-with-Lombok-td4651540.html
Thank you, Setzer
Actually this question is quite old, but since a came across the same issue I want to share my solution anyway.
The best solution I found is this. In deed there's no built-in support for AspectJ in Gradle and the existing plugins (e.g., Gradle AspectJ plugin) do not work with Lombok. So the solution is to enable compile-time weaving in you code manually. A ready to go gradle.build for Java 8 is this
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
}
}
Additional explanation you can find in the article already mentioned above. The build.gradle given here is an updated version of the one given in the article to allow the usage of Java 8 and AspectJ version 1.8.9 and in addition all the unnecessary things are removed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With