gpt4 book ai didi

spring - 升级AspectJ + Spring + Gradle

转载 作者:行者123 更新时间:2023-12-03 06:01:08 24 4
gpt4 key购买 nike

我试图将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在blog post中也对此进行了描述。可能这以某种方式妨碍了项目中其他APT的工作。

不幸的是,ajc的命令行界面没有提及或解释新参数(仅在错误使用它们时显示错误消息),但基本上有3个:-proc-processor-processorpath。在源代码中搜索,甚至可以找到一些内联文档:

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

来自 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);
}

因此,也许您想在调用ajc时在Ant作业中使用 -proc:none,从而避免在另一个构建步骤中对APT进行处理。另一个选择是配置ajc,使其为您执行注释处理,而不是其他APT构建步骤。

关于spring - 升级AspectJ + Spring + Gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41598597/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com