问题
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
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
}
回答1:
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.
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:
From AjcTask.java:
/**
* Controls whether annotation processing and/or compilation is done.
* -proc:none means that compilation takes place without annotation processing.
* -proc:only means that only annotation processing is done, without any subsequent compilation.
*/
public void setProc(String proc) {
if (proc.equals("none")) {
cmd.addFlag("-proc:none", true);
} else if (proc.equals("only")) {
cmd.addFlag("-proc:only", true);
}
}
/**
* -processor class1[,class2,class3...]
* Names of the annotation processors to run. This bypasses the default discovery process.
*/
public void setProcessor(String processors) {
cmd.addFlagged("-processor", processors);
}
/**
* -processorpath path
* Specify where to find annotation processors; if this option is not used, the class path will be searched for processors.
*/
public void setProcessorpath(String processorpath) {
cmd.addFlagged("-processorpath", processorpath);
}
Some test code from AjcTaskTest.java:
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);
}
So maybe you want to use -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.
来源:https://stackoverflow.com/questions/41598597/upgrading-aspectj-spring-gradle