如何使用Maven在没有外部Jar的情况下配置Annotation Processing API? [英] How to configure the Annotation Processing API without external Jar using Maven?
本文介绍了如何使用Maven在没有外部Jar的情况下配置Annotation Processing API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的项目中使用自定义注释.
I would like to use a custom annotation in my project.
如何配置 maven 3 来处理我的注释.AbstractProcessor 类的注释和实现嵌入在我的应用程序中.
How can I configure maven 3 to process my annotation. The annotation and the implementation of the AbstractProcessor class are embedded in my application.
我的注解仅可用于测试(src/test/java).
My annotation is available only for testing (src/test/java).
状态注释:
@Target(ElementType.METHOD)
public @interface State {
boolean success() default true;
}
测试注释处理器:
@SupportedAnnotationTypes("com.*****.client.State")
public class TestAnnotationsProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
System.out.print("TESSST ANNOTATION");
return true;
}
}
我不想把我的注释放在一个外部项目中...这会很愚蠢,因为它真的依赖于我的项目.
我该怎么做?谢谢.
推荐答案
你能不能做点类似的事情(如果语法有点不对,请原谅我,我手边没有 IDE):
Could you do something like (forgive me if the syntax is a little off, I don't have my IDE handy):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin<artifactId>
<version>2.3.2</version>
<executions>
<execution>
<goals>
<goal>testCompile</goal>
</goals>
<phase>test-compile</phase>
<configuration>
<annotationProcessors>com.******.TestAnnotationsProcessor</annotationProcessors>
<proc>only</proc>
</configuration>
</execution>
</executions>
</plugin>
这篇关于如何使用Maven在没有外部Jar的情况下配置Annotation Processing API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文