aspectj.gradle 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. apply plugin: 'java'
  2. configurations {
  3. ajtools
  4. aspectpath
  5. }
  6. dependencies {
  7. ajtools "org.aspectj:aspectjtools:$aspectjVersion"
  8. compile "org.aspectj:aspectjrt:$aspectjVersion"
  9. }
  10. task compileJava(overwrite: true, description: 'Compiles AspectJ Source', type: Ajc) {
  11. dependsOn processResources
  12. sourceSet = sourceSets.main
  13. outputs.dir(sourceSet.classesDir)
  14. aspectPath = configurations.aspectpath
  15. }
  16. task compileTestJava(overwrite: true, description: 'Compiles AspectJ Test Source', type: Ajc) {
  17. dependsOn processTestResources, compileJava, jar
  18. sourceSet = sourceSets.test
  19. outputs.dir(sourceSet.classesDir)
  20. aspectPath = files(configurations.aspectpath, jar.archivePath)
  21. }
  22. class Ajc extends DefaultTask {
  23. SourceSet sourceSet
  24. FileCollection aspectPath
  25. Ajc() {
  26. logging.captureStandardOutput(LogLevel.INFO)
  27. }
  28. @TaskAction
  29. def compile() {
  30. println "Running ajc ..."
  31. ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: project.configurations.ajtools.asPath)
  32. ant.iajc(classpath: sourceSet.compileClasspath.asPath, fork: 'true', destDir: sourceSet.classesDir.absolutePath,
  33. source: project.convention.plugins.java.sourceCompatibility,
  34. target: project.convention.plugins.java.targetCompatibility,
  35. aspectPath: aspectPath.asPath, sourceRootCopyFilter: '**/*.java', showWeaveInfo: 'true') {
  36. sourceroots {
  37. sourceSet.java.srcDirs.each {
  38. pathelement(location: it.absolutePath)
  39. }
  40. }
  41. }
  42. }
  43. }