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.