与 jOOQ , 我可能想结合使用 jOOQ code generator with Maven和一个 custom generator strategy .看起来好像可以这样做(省略不相关的部分):
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>2.2.2</version>
<!-- The plugin should hook into the generate goal -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<generator>
<name>org.jooq.util.DefaultGenerator</name>
<!-- But the custom strategy is not yet compiled -->
<strategy>
<name>com.example.MyStrategy</name>
</strategy>
</generator>
</configuration>
</plugin>
上面的配置描述了问题。 jOOQ 的代码生成器 Hook 到 Maven 生命周期的生成目标,它发生在生命周期的编译目标之前。然而,对于代码生成,它需要一个预编译的自定义策略类,否则我将得到一个 ClassNotFoundException
。如何用 Maven 解决这个问题?我可以在执行 generate
目标之前编译单个类吗?
最佳答案
更好的解决方案是将项目拆分为两个模块。一个包含策略,另一个包含其余部分。
使用模块,您可以在一个独立的步骤中编译策略,然后在插件中使用该模块:
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>2.2.2</version>
...your config goes here...
<dependencies>
list your strategy module here
</dependencies>
</plugin>
关于java - 如何通过 jOOQ 代码生成器和 Maven 使用自定义策略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10322155/