I use JOOQ with a PostgreSQL database. For the moment all the code generated by JOOQ is in the same Maven project.
I would like to know if it is possible to separate the JOOQ code generation in two separate Maven modules:
- in a server module: JOOQ records and DAOs generation
- in a common module: generation of POJOs only.
The objective is to share the common module between the server and the client modules.
The configuration of the target in my generator is as follows:
<target>
<packageName>my.package</packageName>
<directory>target/generated-sources/gen-jooq/</directory>
</target>
Solution I solved my problem based on the second strategy in Lukas Eder's answer.
I have a Jooq generation configuration in the common module. I have another generation configuration in my server module. The 2 configurations share a configuration file for the common parts.
After the generation of the sources, the excess classes are removed by the antrun plugin during the process-sources phase.
The antrun configuration in the common module, only pojos are keeped.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete includeEmptyDirs="true">
<fileset dir="target/generated-sources/gen-jooq/my/package/tables/records/" />
<fileset dir="target/generated-sources/gen-jooq/my/package/tables/" includes="*.java" />
<fileset dir="target/generated-sources/gen-jooq/my/package" includes="*.java" />
</delete>
</target>
</configuration>
</execution>
</executions>
</plugin>
And in the server module, only the pojos are deleted :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete includeEmptyDirs="true">
<fileset dir="target/generated-sources/gen-jooq/my/package/tables/pojos/" />
</delete>
</target>
</configuration>
</execution>
</executions>
</plugin>