gpt4 book ai didi

java - 如何通过 Maven 3.3 运行注释处理?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:42:07 24 4
gpt4 key购买 nike

多年来,我们一直将 maven-processor-plugin 作为一个单独的目标运行(在 maven-compiler-plugin 上使用 proc:none)。我们终于从 maven 3.0.5 升级到最新的 3.3.3,我看到 maven-processor-plugin 基本上看起来已经死了。据我所知,它还没有从谷歌代码中迁移出来。

我们主要使用注释处理来生成 Dagger 类。我不记得原因了,但当时(在 dagger-1 中),我们的印象是在 generate-sourcesgenerate-test-sources< 期间这样做更好 阶段,而不是在 compiletest-compile 期间,这就是我们一开始使用 maven-processor-plugin 的原因。请注意,我们希望这一切在 eclipse/m2e 中也能很好地发挥作用。

是否有一种新的、更好的方法来从对 eclipse 友好的 maven 运行注释处理?

最佳答案

您可以使用maven-compiler-plugin 进行注释处理,因为该功能存在于javac 中。要在不同的阶段进行注释处理和定期编译,您可以多次执行插件,一次使用 annotation processing turned on。 ,另一个关闭。其配置如下:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<executions>
<execution>
<id>process-annotations</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<compilerArgs>
<arg>-proc:only</arg>
<arg>-processor</arg>
<arg>MyAnnotationProcessor</arg>
</compilerArgs>
</configuration>
</execution>
<execution>
<id>default-compile</id> <!-- using an id of default-compile will override the default execution -->
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<compilerArgs>
<arg>-proc:none</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>

关于java - 如何通过 Maven 3.3 运行注释处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32194069/

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