aspectj.gradle 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. aspectPath = configurations.aspectpath
  14. }
  15. task compileTestJava(overwrite: true, description: 'Compiles AspectJ Test Source', type: Ajc) {
  16. dependsOn processTestResources, compileJava, jar
  17. sourceSet = sourceSets.test
  18. aspectPath = files(configurations.aspectpath, jar.archivePath)
  19. }
  20. class Ajc extends DefaultTask {
  21. @Input
  22. SourceSet sourceSet
  23. @Input
  24. FileCollection aspectPath
  25. @TaskAction
  26. def compile() {
  27. println "Running ajc ..."
  28. ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: project.configurations.ajtools.asPath)
  29. ant.iajc(classpath: sourceSet.compileClasspath.asPath, fork: 'true', destDir: sourceSet.classesDir.absolutePath,
  30. source: project.convention.plugins.java.sourceCompatibility,
  31. target: project.convention.plugins.java.targetCompatibility,
  32. aspectPath: aspectPath.asPath, sourceRootCopyFilter: '**/*.java', showWeaveInfo: 'true') {
  33. sourceroots {
  34. sourceSet.java.srcDirs.each {
  35. pathelement(location: it.absolutePath)
  36. }
  37. }
  38. }
  39. }
  40. }