[英]Javac not running annotation processors
I'm revisiting a maven project that I haven't touched in at least a year.我正在重新审视我至少一年没有接触过的 maven 项目。 I'm pretty sure it was compiling successfully when I left it (there was still a working jar in the
target
directory), but now compilation fails because generated classes are missing.我很确定当我离开它时它编译成功(
target
目录中仍然有一个工作 jar),但现在编译失败,因为缺少生成的类。
target/generated-sources/annotations
( none present )target/generated-sources/annotations
中确实没有源(不存在)-proc:none
( it wasn't )-proc:none
调用 javac(不是)mvn clean dependency:unpack-dependencies -Dmdep.useSubDirectoryPerArtifact=true
to ensure the expected dependencies are on the classpath and that they contain a valid META-INF/services/javax.annotation.processing.Processor
entry ( yes there were multiple, including org.immutables.processor.ProxyProcessor
) mvn clean dependency:unpack-dependencies -Dmdep.useSubDirectoryPerArtifact=true
以确保预期的依赖项位于类路径上,并且它们包含有效的META-INF/services/javax.annotation.processing.Processor
条目(是的,有多个,包括org.immutables.processor.ProxyProcessor
)-nowarn
option and add -verbose -XprintRounds -XprintProcessorInfo -Xlint -J-verbose
.-nowarn
选项并添加-verbose -XprintRounds -XprintProcessorInfo -Xlint -J-verbose
。 NOTE: I also had to add the relative path to the main class, or javac would complain there are no sources.-proc:only
option to javac command-proc:only
选项-processor org.immutables.processor.ProxyProcessor
to javac command ( processor now loaded , but still no rounds printed and no classes generated) -processor org.immutables.processor.ProxyProcessor
添加到 javac 命令(处理器现在已加载,但仍然没有打印轮次,也没有生成类)-processor org.immutables.processor.ProxyProcessorXXX
to see if it would make a difference ( it did , it now printed a warning stating that processing was requested with proc:only
, but no processors were found)-processor org.immutables.processor.ProxyProcessorXXX
以查看它是否会有所作为(确实如此,它现在打印一条警告,指出使用proc:only
请求处理,但未找到处理器)-processor
option, which should make javac detect processors from class path ( it didn't show the warning, which suggests it's detecting processors yet the log doesn't show any sign of it)-processor
选项是否出现该警告,这应该使 javac 从 class 路径检测处理器(它没有显示警告,这表明它正在检测处理器但日志没有显示任何迹象其中)This is the javac command I'm currently using:这是我目前使用的 javac 命令:
javac -d./target/classes -classpath./target/classes:$HOME/.m2/repository/com/google/dagger/dagger/2.4/dagger-2.4.jar:$HOME/.m2/repository/com/google/dagger/dagger-compiler/2.4/dagger-compiler-2.4.jar:$HOME/.m2/repository/com/google/auto/factory/auto-factory/1.0-beta3/auto-factory-1.0-beta3.jar:$HOME/.m2/repository/org/immutables/builder/2.3.9/builder-2.3.9.jar:$HOME/.m2/repository/org/immutables/value/2.3.9/value-2.3.9.jar:<LONG LIST OF DIRECT AND TRANSITIVE DEPENDENCIES HERE> -sourcepath./src/main/java: -s./target/generated-sources/annotations -verbose -XprintRounds -XprintProcessorInfo -Xlint -J-verbose -processor org.immutables.processor.ProxyProcessor -proc:only./src/main/java/com/mycompany/myproject/Main.java
NOTE : for better readability, I put each argument on a new line, replaced absolute paths with $HOME/
and ./
and I omitted most dependencies.注意:为了更好的可读性,我将每个参数放在一个新行上,用
$HOME/
和./
替换了绝对路径,并且我省略了大多数依赖项。
What am I missing here?我在这里想念什么? Any suggestions or pointers would be greatly appreciated.
任何建议或指示将不胜感激。
As far as I can remember maven generates a marker file or marker directory (starting with a dot) for generated sources. 据我所知,maven为生成的源生成一个标记文件或标记目录(以点开头)。 But it's also a long time ago...
但也是很久以前......
We had the same issue on a git branch, while the main branch built fine.我们在 git 分支上遇到了同样的问题,而主分支构建良好。 The root cause turned out to be a.java source with a duplicate definition of a private void function.
根本原因原来是 a.java 源具有重复定义的私有 void function。 This duplicate was caused by a merge from the main branch.
这个重复是由主分支的合并引起的。 At first we did not notice it, because the merge did not cause conflicts.
起初我们没有注意到它,因为合并没有引起冲突。 The problem occurred with Amazon Corretto 8 and 11 compilers.
Amazon Corretto 8 和 11 编译器出现此问题。 After removing the duplicate private void function, the java compiler started generating sources as before.
删除重复的私有 void function 后,java 编译器像以前一样开始生成源。
javac
appears to completely and silently skip annotation processing for some parse failures.对于某些解析失败,
javac
似乎完全且静默地跳过注释处理。
For me a duplicated annotation caused by a merge mistake caused thousands of failures because my annotation processors didn't run - so the real error got completely lost.对我来说,由于我的注释处理器没有运行,由合并错误引起的重复注释导致了数千次失败 - 所以真正的错误完全丢失了。
@Data @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode(callSuper = false)
@EqualsAndHashCode(callSuper = false)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.