【发布时间】:2021-04-27 07:25:53
【问题描述】:
我目前正在开发一个 java 项目,我需要在其中生成和编译 JPA 元模型类作为构建的一部分。我做了一些研究并在这里找到了答案:Generate the JPA metamodel files using maven-processor-plugin - What is a convenient way for re-generation? 这似乎是一个合理的解决方案。问题是,我的项目还包含一些需要与 java.util 一起编译的 groovy 类。如果我启用 maven-processor-plugin,maven 构建将在遇到依赖于 groovy 类的 java 类时立即失败。查看控制台输出,我可以看到 maven-processor-plugin 在 groovy 编译器之前运行,因此那些 groovy 类没有机会被编译。
有没有人知道有什么好的方法来处理这个问题?有什么方法可以将编译过程分成几个阶段,以便我可以控制什么时候处理什么?
这是我的 pom.xml 的 sn-p:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<showWarnings>false</showWarnings>
<compilerId>groovy-eclipse-compiler</compilerId>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>3.6.0-03</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>3.0.7-02</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>4.5-jdk8</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>${project.build.directory}/../src/main/generated-sources/java/jpametamodel</outputDirectory>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.3.13.Final</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/../src/main/generated-sources/java/jpametamodel</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
【问题讨论】:
-
处理器插件是否在您的 Java 源代码上运行?编译之后会发生吗?如果需要先编译,我认为处理器运行时相位控制的选择。
标签: java maven jpa groovy annotations