我有一个 Maven 项目,我需要在其中执行两个代码生成步骤。一个生成一些 Java 类型,然后第二个依赖于这些 Java 类型来生成更多代码。有没有办法在我的构建过程中同时执行这两个步骤?
目前我的步骤是:
- 执行第一个代码生成插件(在
generate-sources
期间) - 将生成类型的目录添加到构建路径
- 执行第二个代码生成插件(在
编译
期间)
但是我的问题是,第二个代码生成插件生成的任何东西都不会被编译(因为编译阶段已经完成)。如果我将第二个代码生成插件附加到较早的阶段,它会失败,因为它需要第一个代码生成插件中的类出现在类路径中。
我知道我可以将它分成两个模块,一个依赖另一个模块,但我想知道这是否可以在一个 pom.xml 中实现。似乎需要一种在正常编译阶段完成后再次调用编译的方法。
有什么想法吗?
最佳答案
您始终可以配置编译器插件的两次执行,都与编译阶段相关联。在一个你包括额外的东西:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>one</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration></configuration>
</execution>
<execution>
<id>two</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jar</compilerArgument>
</configuration>
</execution>
</executions>
<plugin>
你也可以试试<includes><include>path/</include></includes>
When multiple executions are given that match a particular phase, they are executed in the order specified in the POM, with inherited executions running first.
但我不太明白你到底想要什么。 http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
关于java - 编译阶段后通过 Maven 插件生成新源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4595544/