我有一个依赖于aspectj的java模块。当我在java项目中使用该模块时,我只是告诉maven使用aspectj-maven-plugin(mojo)并使用ajcCompiler编译项目。步骤来自Maven + AspectJ - all steps to configure it
现在我有一个grails项目,我需要在那里使用该模块。因此,据我所知,我需要将编译器覆盖到
ant.property(name:'build.compiler', value:'org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter')
_Events.groovy中的:eventCompileStart闭包。这不起作用,所以还有另一个建议是在eventCompileEnd上添加一个iajc任务(http://permalink.gmane.org/gmane.comp.lang.groovy.grails.user/127215)
我该如何做到这一点?我不确定这个过程!顺便说一下,我有'org.codehaus.mojo:aspectj-maven-plugin:1.4'定义为buildConfig.groovy上的编译时依赖
[更新]
我在_Events.groovy
中定义了这个ant.taskdef( resource:"org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajc.asPath)
ant.iajc(destDir: grails.compile.classpath, source: "1.7", target:"1.7", ) {
classpathref(dir: classesDirPath)
}
这应该“起作用”,但事实并非如此!我错过了什么?
答案 0 :(得分:1)
两步解决方案:
定义IAJC任务:
ant.taskdef(name: 'iajc', classname: 'org.aspectj.tools.ant.taskdefs.AjcTask')
执行IAJC任务来编织已编译的类
String aspectjrtPath = "path to your aspectjrt.jar"
String classesDirPath = "path to the compiled classes you're weaving"
ant.iajc(classpath: aspectjrtPath, destdir: classesDirPath) {
inpath() {
pathelement(path: classesDirPath)
}
aspectpath() {
pathelement(path: icnTraceLibrary)
}
}
这解决了我的问题,目标现在用我的跟踪框架编织。