简体   繁体   English

Maven 3.0.4 - 编译后执行注释处理器

[英]Maven 3.0.4 - execute annotation processors after compile

I would like to run the following basic procedure within my Maven 3.0.4 project. 我想在我的Maven 3.0.4项目中运行以下基本过程。 I have all the basics in place and haven't had any issues but am running into problems on step #3. 我已经掌握了所有基础知识并且没有遇到任何问题,但在第3步遇到了问题。 For some reason the basic solution is eluding me, since it seems like something that should be very obvious. 出于某种原因,基本的解决方案是逃避我,因为它似乎应该非常明显。

  1. Run a basic clean/install (without annotation processing) 运行基本的清理/安装(没有注释处理)
  2. Request that a site build be run 请求运行站点构建
  3. Before the site build kicks off, run annotation processing on the compiled classes using an annotation processor class that was compiled in the initial steps 在站点构建开始之前, 使用在初始步骤中编译的注释处理器类对编译的类运行注释处理

I tried setting up the annotation processing goal as follows: 我尝试设置注释处理目标如下:

<plugin>
  <groupId>org.bsc.maven</groupId>
  <artifactId>maven-processor-plugin</artifactId>
  <executions>
    <execution>
      <id>process</id>
      <goals>
        <goal>process</goal>
      </goals>
      <phase>pre-site</phase>
      <configuration>
        <outputDirectory>${basedir}/target/generated-documentation</outputDirectory>
        <processors>
          <processor>com.mydomain.MyFancyAnnotationProcessor</processor>
        </processors>
      </configuration>
    </execution>
  </executions>
</plugin>

For some reason this doesn't seem to be working. 出于某种原因,这似乎不起作用。 I feel like I'm doing something very, very silly that is preventing it from working. 我觉得我正在做一些非常非常愚蠢的事情,这使得它无法正常工作。

I am using the Maven Annotation Plugin instead of the basic, Mojo Apt Plugin . 我正在使用Maven Annotation插件而不是基本的Mojo Apt插件 I don't mind switching if someone has a working solution with that one. 如果某人有一个有效的解决方案,我不介意切换。 I tried both without any immediate signs of success. 我没有任何立即成功的迹象我试过了。 Again, it feels like it's just something obvious that I'm overlooking. 再一次,感觉它只是我忽略的一些明显的东西。

Error received: 收到错误:

[INFO] diagnostic error: Annotation processor 'com.mydomain.MyFancyAnnotationProcessor' not found
[ERROR] error on execute: error during compilation

My guess would be that the plugin is not including the current project itself in its classpath. 我的猜测是插件不包括当前项目本身的类路径。 The best solution would be to separate the annotation processor into its own (sub-)module if possible. 最好的解决方案是尽可能将注释处理器分离到自己的(子)模块中。 If you can't do that, you may be able to just add this project itself as a dependency of the plugin (using a <dependencies> section under the plugin node). 如果你不能这样做,你或许可以将这个项目本身作为插件的依赖项添加(使用插件节点下的<dependencies>部分)。

As a diagnostic note, you can run maven with the '-X' argument to see detailed info about the build. 作为诊断说明,您可以使用'-X'参数运行maven以查看有关构建的详细信息。 This should show you exactly what is on the classpath when the plugin is executed. 这应该会显示插件执行时类路径上的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM