升级AspectJ + Spring + Gradle [英] upgrading AspectJ + Spring + Gradle
问题描述
我正在尝试将AspectJ jar从1.8.1升级到1.8.5,但是我的构建始终失败,并出现以下错误:
I am trying to upgrade the AspectJ jar from 1.8.1 to 1.8.5 but my build keeps failing with the following error:
[ant:iajc] [error] javax.annotation.processing.FilerException: createResource. Resource already created
在更新之前,构建良好.我尝试从1.8.1升级到1.8.2,但同样失败. 这是我的build.gradle的一个片段
The build was fine before the update. I tried to do another upgrade from 1.8.1 to 1.8.2 and that failed as well. Here is a snippet of my 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
}
推荐答案
由于博客文章中也对此进行了描述维护者安迪·克莱门特(Andy Clement).可能以某种方式妨碍了项目中其他APT的工作.
Since AspectJ 1.8.2 the AspectJ compiler ajc supports annotation processing. This was also described in a blog post by AspectJ maintainer Andy Clement. Probably this is somehow getting in the way of other APT stuff in your project.
不幸的是, ajc 的命令行界面没有提及或解释新参数(错误使用时仅显示错误消息),但是基本上有三个:-proc
,-processor
和-processorpath
.在源代码中搜索,甚至可以找到一些内联文档:
Unfortunately, the command line interface for ajc does not mention or explain the new parameters (only showing error messages when using them wrongly), but basically there are three: -proc
, -processor
and -processorpath
. Searching in the source code, you even find some inline documentation:
来自
来自 AjcTaskTest.java : 因此,也许您想在调用 ajc 时在Ant作业中使用 So maybe you want to use 这篇关于升级AspectJ + Spring + Gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! public void testAptProc() {
AjcTask task = getTask(NOFILE);
task.setProc("none");
checkContains(task.makeCommand(), "-proc:none", true);
task.setProc("only");
checkContains(task.makeCommand(), "-proc:only", true);
}
public void testAptProcessor() {
AjcTask task = getTask(NOFILE);
task.setProcessor("some.SomeClass");
checkContains(task.makeCommand(), "-processor", true);
checkContains(task.makeCommand(), "some.SomeClass", true);
}
public void testAptProcessorpath() {
AjcTask task = getTask(NOFILE);
task.setProcessorpath("some/path");
checkContains(task.makeCommand(), "-processorpath", true);
checkContains(task.makeCommand(), "some/path", true);
}
public void testAptGeneratedDirectory() {
AjcTask task = getTask(NOFILE);
task.setS("some/path");
checkContains(task.makeCommand(), "-s", true);
checkContains(task.makeCommand(), "some/path", true);
}
-proc:none
,以便在另一构建步骤中摆脱对APT的处理方式.另一种选择是配置 ajc ,使其为您执行注释处理,而不是其他APT构建步骤.-proc:none
in your Ant job when calling ajc so as go step out of the way of what you do with APT in another build step. The other option would be to configure ajc such that it does the annotation processing for you instead of the other APT build step.