def aspectjVersion = "1.8.0.M1"

configurations {
	aspects
	ajInpath
}

dependencies {
	tools "org.aspectj:aspectjtools:$aspectjVersion"
	compile "org.aspectj:aspectjrt:$aspectjVersion"
	compile("cglib:cglib:2.2.2") { exclude group: 'asm' } // cglib 2.2.2 depends on asm 3.3
        compile 'org.ow2.asm:asm:5.0_BETA'
	compile 'org.ow2.asm:asm-tree:5.0_BETA'
	compile files("code.jar")
}

compileJava.deleteAllActions()

task aspectJ(dependsOn: JavaPlugin.PROCESS_RESOURCES_TASK_NAME)  {
	dependsOn configurations.tools.getTaskDependencyFromProjectDependency(true, "compileJava")
	def srcDirs = sourceSets.main.java.srcDirs
	srcDirs.each { inputs.dir it }
	def destDir = sourceSets.main.output.classesDir
	outputs.dir destDir
	doLast {
		ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.tools.asPath)

		ant.iajc(source:sourceCompatibility, target:targetCompatibility, destDir: destDir.absolutePath, maxmem:"512m", fork:"true",
		aspectPath: configurations.aspects.asPath, inpath:configurations.ajInpath.asPath, sourceRootCopyFilter:"**/.svn/*,**/*.java",classpath:configurations.compile.asPath ){
			sourceroots {
				srcDirs.each {
					if (it.exists()) pathelement location: it.absolutePath
				}
			}
		}
	}
}

compileJava.dependsOn aspectJ

