I am trying to use the AspectJ compiler on my Spring project. However, I am having classpath issues. For projects in that depend on other projects I am getting type resolution errors. I think this is due to ‘sourceSets.main.compileClasspath.asPath’ including project dependencies by including a resulting artifact rather than just using the class files. This is a problem because the task dependencies for ‘compileJava’ don’t including buidling the artifacts for dependent projects. Does anybody know you set the appropriate classpath for the AspectJ compiler when you have project dependencies?
Below is the configuration I am using for the AspectJ compiler. It is based on this https://github.com/SpringSource/spring-security/blob/master/buildSrc/src/main/groovy/aspectj/AspectJPlugin.groovy :
configurations {
ajc
springAspects
ajInpath
}
dependencies {
ajc 'org.aspectj:aspectjtools:1.7.2'
springAspects 'org.springframework:spring-aspects:3.0.5.RELEASE'
compile "org.aspectj:aspectjrt:1.7.2"
compile "javax.persistence:persistence-api:1.0"
}
task compileJava(dependsOn: configurations.compile.getTaskDependencyFromProjectDependency(true, "compileJava"), overwrite: true) << {
ant.taskdef( resource:"org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajc.asPath)
ant.iajc(
source:sourceCompatibility,
target:targetCompatibility,
destDir:sourceSets.main.output.classesDir.absolutePath,
maxmem:"512m",
fork:"true",
aspectPath:configurations.springAspects.asPath,
inpath:configurations.ajInpath.asPath,
sourceRootCopyFilter:"**/*.java",
classpath: sourceSets.main.compileClasspath.asPath){
sourceroots{
sourceSets.main.java.srcDirs.each{
pathelement(location:it.absolutePath)
}
}
}
}