13

对于jOOQ,我可能希望将jOOQ 代码生成器与 Maven自定义生成器策略结合使用。看起来好像可以这样做(省略不相关的部分):

<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 的代码生成器与 Maven 生命周期的 generate 目标挂钩,该目标发生在生命周期的 compile 目标之前。然而,对于代码生成,它需要一个预编译的自定义策略类,否则我会得到一个ClassNotFoundException. Maven如何解决这个问题?generate我可以在执行目标之前编译一个类吗?

4

1 回答 1

7

一个更好的解决方案是将项目分成两个模块。一个包含策略,另一个包含其余部分。

使用模块,您可以在一个独立的步骤中编译策略,然后在插件中使用该模块:

<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>
于 2012-06-08T09:29:16.573 回答