如何使用jOOQ代码生成器和Maven的自定义策略? [英] How to use a custom strategy with the jOOQ code-generator and Maven?

查看:162
本文介绍了如何使用jOOQ代码生成器和Maven的自定义策略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 jOOQ ,我可能想要使用使用Maven的jOOQ代码生成器自定义生成器策略。这看起来好像可以这样做(省略不相关的部分):

With jOOQ, I may want to combine using the jOOQ code generator with Maven and a custom generator strategy. It looks as though this can be done as such (leaving out irrelevant parts):

<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生命周期的生成目标,该生成目标发生在生命周期的编译目标之前。但是,对于代码生成,它需要预编译的自定义策略类,否则我将获得 ClassNotFoundException 。如何用Maven解决这个问题?我可以在执行生成目标之前编译单个类吗?

The above configuration depicts the problem. jOOQ's code generator hooks into the generate goal of the Maven lifecycle, which takes place before the compile goal of the lifecycle. For code generation, however, it needs a pre-compiled custom strategy class, or I will get a ClassNotFoundException. How can this be resolved with Maven? Can I compile a single class before executing the generate goal?

推荐答案

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

A much better solution is to split the project into two modules. One contains the strategy and the other the rest.

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

Using modules, you can compile the strategy in an independent step and then use that module in the plugin:

<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>

这篇关于如何使用jOOQ代码生成器和Maven的自定义策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆