Tech stack - #java, #maven, #liquibase, #docker
Why?
I will talk about what we did to achieve below things,
Generate jooq-classes from an in-memory or Adhoc database instead of connecting to prelive/live environments.
How to apply all the migrations using liquibase before generating jooq-classes.
Generate jooq-classes based on Postgres driver. Jooq supports generating classes connecting to h2 (in-memory database) but not Postgres. We use Postgres mostly and h2 mostly does not support many features Postgres has.
Avoid using multiple maven plugins and 100 lines of code instead use one maven plugin.
What we did
Start "Test-containers" during maven pre-compile stage. (https://www.testcontainers.org/#about)
Apply liquibase migrations over the test-container.
Generate jooq-classes based for the schema provided.
Where can I find
jango89 / jooqgen-liquibase-postgres
Maven plugin with jooq, liquibase and postgres
What is this
Maven plugin which can be integrated to any maven project Sample :
<plugin>
<groupId>com.mytaxi</groupId>
<artifactId>jooqgen-liquibase-postgres</artifactId>
<configuration>
<schema>bookingoptionsservice</schema> <-- schema name -->
<packageName>com.mytaxi.bookingoptionsservice</packageName> <-- package to be created for generated classes -->
<liquibaseChangeLogFile>${liquibase.changeLogFile}</liquibaseChangeLogFile>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>jooqOverPostgresContainer</goal>
</goals>
</execution>
</executions>
</plugin>
What it does
- Starts a postgress docker container.
- Applies liquibase changes over the container.
- Generates JOOQ classes for the source project connecting to postgres container.
Problems and solutions
If generated classes fail to compile,
- include
/target/generated-sources/jooq/
folder to corresponding compiler plugin. - If kotlin-maven-plugin compilation failes, add
<configuration> <sourceDirs> <source>src/main/java</source> <source>target/generated-sources/jooq</source> </sourceDirs> </configuration>
- If the
NoClassDefError
happens, this means the class files are missing. Add the following plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/jooq</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Top comments (1)
Nice work!!!