1

我有一个依赖于 aspectj 的 java 模块。当我在 java 项目中使用该模块时,我只是告诉 maven 使用 aspectj-maven-plugin (mojo) 并使用 ajcCompiler 编译项目。步骤继承自Maven + AspectJ - 配置它的所有步骤

现在我有一个 grails 项目,我需要在那里使用该模块。因此,据我了解,我需要重写编译器以

ant.property(name:'build.compiler', value:'org.aspectj.tools.ant.taskdefs.Ajc11CompilerAdapter')

在 _Events.groovy:eventCompileStart 关闭。这不起作用,因此还有另一个建议是在 eventCompileEnd ( http://permalink.gmane.org/gmane.comp.lang.groovy.grails.user/127215 )上添加 iajc 任务

我该怎么做?我不确定这个过程!顺便说一句,我将 '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)
}

这“应该”有效,但当然不行!我错过了什么?

4

1 回答 1

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)
  }
}

这解决了我的问题,目标现在与我的跟踪框架交织在一起。

于 2013-08-06T20:43:52.680 回答