How to use a custom strategy with the jOOQ code-generator and Maven?

两盒软妹~` 提交于 2019-12-10 01:56:54

问题


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>

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?


回答1:


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>


来源:https://stackoverflow.com/questions/10322155/how-to-use-a-custom-strategy-with-the-jooq-code-generator-and-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!