【发布时间】:2018-07-01 00:00:27
【问题描述】:
出于测试原因,我编写了一个 AnnotationProcessor,它不是由 maven 执行的。
我正在使用 google 的“自动服务”为我创建 META-INF 数据。
这是处理器:
@SupportedAnnotationTypes({ "test.TestAnnotation" })
@SupportedSourceVersion(SourceVersion.RELEASE_8)
@AutoService(Processor.class)
public class AnnotationProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
System.out.println("Test");
this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Test");
return true;
}
}
我也尝试过抛出异常、创建文件、使用断点运行 mvnDebug 等等。对我来说没有任何效果。
这是项目中提供处理器的重要部分(剩下的只是groupId、命名等):
<dependencies>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.0-rc4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
这是项目 POM 的重要部分,它使用注释进行代码生成:
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Annotation</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
</plugins>
</build>
我的最终目标是让项目将我的注释处理器添加为依赖项并准备好使用(有点像 lombok)。
编辑 测试注释正在测试类上使用。
【问题讨论】:
标签: java maven annotations annotation-processing