apply id: 'java' configurations { ajtools aspectpath } dependencies { ajtools "org.aspectj:aspectjtools:$aspectjVersion" compile "org.aspectj:aspectjrt:$aspectjVersion" } task compileJava(dependsOn: JavaPlugin.PROCESS_RESOURCES_TASK_NAME, overwrite: true, description: 'Compiles AspectJ Source') << { println "Running ajc ..." ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajtools.asPath) ant.iajc(classpath: configurations.compile.asPath, fork: 'true', destDir: sourceSets.main.classesDir.absolutePath, source: sourceCompatibility, target: targetCompatibility, aspectPath: configurations.aspectpath.asPath, sourceRootCopyFilter: '**/*.java') { sourceroots { sourceSets.main.java.srcDirs.each { pathelement(location: it.absolutePath) } } } }