Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 913
Lukas Eder Avatar asked Apr 25 '12 19:04

Lukas Eder


1 Answers

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>
like image 110
Aaron Digulla Avatar answered Oct 11 '22 14:10

Aaron Digulla