我正在尝试将 AspectJ jar 从 1.8.1 升级到 1.8.5,但我的构建一直失败并出现以下错误:
[ant:iajc] [error] javax.annotation.processing.FilerException: createResource. Resource already created
更新前的构建很好。我尝试从 1.8.1 升级到 1.8.2,但也失败了。这是我的 build.gradle 的片段
ext.aspectjCompiler = {
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.aspects.asPath,
sourceRootCopyFilter:'**/*.java',
classpath: "${configurations.compile.asPath};${configurations.aspectCompile.asPath}",
Xlint: 'ignore'
){
sourceroots {
sourceSets.main.java.srcDirs.each { srcDir ->
pathelement(location: srcDir.absolutePath)
}
}
}
}
compileJava {
doLast aspectjCompiler
}
从AspectJ 1.8.2 开始,AspectJ 编译器ajc支持注释处理。AspectJ 维护者 Andy Clement在博客文章中也描述了这一点。可能这会以某种方式妨碍您项目中的其他 APT 内容。
遗憾的是,ajc的命令行界面并没有提及或解释新参数(仅在错误使用时显示错误消息),但基本上有三个:
-proc
,-processor
和-processorpath
。在源代码中搜索,您甚至可以找到一些内联文档:从AjcTask.java:
来自AjcTaskTest.java的一些测试代码:
因此,也许您想在调用ajc
-proc:none
时在 Ant 作业中使用,以便在另一个构建步骤中避开您使用 APT 所做的事情。另一个选项是配置ajc以便它为您执行注释处理,而不是其他 APT 构建步骤。