Skip to content

raman-babich/dbljc-mysqlljc-maven-plugin

Repository files navigation

Mysql liquibase jooq codegen maven plugin (mysqlljc)

This maven plugin is a composition of liquibase maven plugin update goal and jooq codegen maven plugin generate goal with dockerized mysql 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.

Quick start

Simply add mysqlljc 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>mysqlljc-maven-plugin</artifactId>
  <version>${mysqlljc-maven-plugin.version}</version>
  <configuration>
    <mysqlDockerImageName>mysql:8.0.33</mysqlDockerImageName>
    <mysqlJdbcDriverVersion>8.0.33</mysqlJdbcDriverVersion>
    <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/mysqlljcmavenplugin/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.mysqlljcmavenplugin.jooq</packageName>
        </target>
      </generator>
    </jooqConfiguration>
  </configuration>
  <executions>
    <execution>
      <id>mysqlljc-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.

Internals

The mysqlljc 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 (MySQLContainer<?> mysql = new MySQLContainer<>(mysqlDockerImageName)) {
  mysql.start();
  MojoExecutor.executeMojo(
      liquibaseMavenPlugin(liquibaseMavenPluginVersion, mysqlJdbcDriverVersion),
      MojoExecutor.goal(LIQUIBASE_MAVEN_PLUGIN_GOAL),
      setLiquibaseDbConnectionValues(liquibaseConfiguration, mysql),
      MojoExecutor.executionEnvironment(project, session, buildPluginManager));
  MojoExecutor.executeMojo(
      jooqCodegenMavenPlugin(jooqCodegenMavenPluginVersion, mysqlJdbcDriverVersion),
      MojoExecutor.goal(JOOQ_CODEGEN_MAVEN_PLUGIN_GOAL),
      setJooqDbConnectionValues(jooqConfiguration, mysql),
      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.

License

Licensed under the Apache License, Version 2.0