This maven plugin is a composition of liquibase maven plugin update
goal and jooq codegen maven
plugin generate
goal with containerized postgres running in context of these two goals.
It was created many years ago but open sourced only in 2023. And now there is another project that could help you to do similar thing, and it will be fair to mention it, so you can choose plugin that fits you the best.
You can find some other related plugins within dbljc project.
Simply add pgljc maven plugin
to your pom and specify generate
goal in the executions section.
You can walk through the listing below to get the idea of plugin configuration. All properties
related to database connection will be handled by plugin for you.
<plugin>
<groupId>com.ramanbabich.dbljc</groupId>
<artifactId>pgljc-maven-plugin</artifactId>
<version>${pgljc-maven-plugin.version}</version>
<configuration>
<postgresDockerImageName>postgres:15.3-alpine</postgresDockerImageName>
<postgresJdbcDriverVersion>42.6.0</postgresJdbcDriverVersion>
<liquibaseMavenPluginVersion>4.22.0</liquibaseMavenPluginVersion>
<jooqCodegenMavenPluginVersion>3.18.4</jooqCodegenMavenPluginVersion>
<liquibaseConfiguration>
<!-- this section is the configuration section of the liquibase maven plugin to execute
update goal, you can find more details on the official site.
https://docs.liquibase.com/tools-integrations/maven/commands/maven-update.html -->
<changeLogFile>/com/ramanbabich/dbljc/pgljcmavenplugin/liquibase/changelog/db.changelog-master.yaml</changeLogFile>
</liquibaseConfiguration>
<jooqConfiguration>
<!-- this section is the configuration section of the jooq codegen maven plugin to execute
generate goal, you can find more details on the official site.
https://www.jooq.org/doc/latest/manual/code-generation/codegen-maven/ -->
<generator>
<database>
<inputSchema>public</inputSchema>
</database>
<target>
<packageName>com.ramanbabich.dbljc.pgljcmavenplugin.jooq</packageName>
</target>
</generator>
</jooqConfiguration>
</configuration>
<executions>
<execution>
<id>pgljc-generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
Note
|
Internal structures of liquibaseConfiguration and jooqConfiguration sections are
dynamic and heavily depend on the versions provided in liquibaseMavenPluginVersion and
jooqCodegenMavenPluginVersion accordingly.
|
The pgljc maven plugin internally uses liquibase-maven-plugin, jooq-codegen-maven-plugin, testcontainers and mojo-executor. And the tiny thing this plugin do could be described with a few lines of code.
try (PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(postgresDockerImageName)) {
postgres.start();
MojoExecutor.executeMojo(
liquibaseMavenPlugin(liquibaseMavenPluginVersion, postgresJdbcDriverVersion),
MojoExecutor.goal(LIQUIBASE_MAVEN_PLUGIN_GOAL),
setLiquibaseDbConnectionValues(liquibaseConfiguration, postgres),
MojoExecutor.executionEnvironment(project, session, buildPluginManager));
MojoExecutor.executeMojo(
jooqCodegenMavenPlugin(jooqCodegenMavenPluginVersion, postgresJdbcDriverVersion),
MojoExecutor.goal(JOOQ_CODEGEN_MAVEN_PLUGIN_GOAL),
setJooqDbConnectionValues(jooqConfiguration, postgres),
MojoExecutor.executionEnvironment(project, session, buildPluginManager));
}
Note
|
If you are curious enough, this plugin implementation contains only one java file, so don’t be scared to look through it. |