Home > Software engineering >  jOOQ auto-generator is not running after liquibase update on doing mvn clean compile
jOOQ auto-generator is not running after liquibase update on doing mvn clean compile

Time:03-22

I want jOOQ to auto-generate code based on the liquibase schema xml file that I have provided (not on basis of db connection). If I change something in liquibase xml file, the change reflects in the database, but I am not able the new auto-generated code. I have to run mvn clean compile twice in order for jOOQ to understand the change.

The generator part of my pom.xml looks like this. Please help:

<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.16.3.xsd">
    <jdbc>
        <driver>org.postgresql.Driver</driver>
        <url>${spring.datasource.url}</url>
        <user>${spring.datasource.username}</user>
        <password>${spring.datasource.password}</password>
    </jdbc>
    <generator>
        <database>
            <name>org.jooq.meta.extensions.liquibase.LiquibaseDatabase</name>
            <name>org.jooq.meta.postgres.PostgresDatabase</name>
            <properties>

                <!-- Specify the classpath location of your XML, YAML, or JSON script. -->
                <property>
                    <key>scripts</key>
                    <value>liquibase-outputChangeLog.xml</value>
                </property>

                <!-- Whether you want to include liquibase tables in generated output

                     - false (default)
                     - true: includes DATABASECHANGELOG and DATABASECHANGELOGLOCK tables -->
                <property>
                    <key>includeLiquibaseTables</key>
                    <value>true</value>
                </property>

                <!-- Properties prefixed "database." will be passed on to the liquibase.database.Database class
                     if a matching setter is found -->
               
                <!-- The property "changeLogParameters.contexts" will be passed on to the
                     liquibase.database.Database.update() call (jOOQ 3.13.2 ).
                     See https://www.liquibase.org/documentation/contexts.html -->
                <property>
                    <key>changeLogParameters.contexts</key>
                    <value>!test</value>
                </property>
            </properties>
            <inputSchema>public</inputSchema>
        </database>
    </generator>
</configuration>

CodePudding user response:

The problem your question is about

By adding the PostgresDatabase in addition to the LiquibaseDatabase, you just override the LiquibaseDatabase configuration for that <name/> element. You can't specify multiple of those.

The problem you were trying to solve

Please look at the documentation for jOOQ's LiquibaseDatabase. It mentions that the scripts property should describe a classpath location of your migration file, not a relative path location, e.g.

<!-- Specify the classpath location of your XML, YAML, or JSON script. -->
<property>
  <key>scripts</key>
  <value>/database.xml</value>
</property>

(Note the slash at the beginning). Starting from jOOQ 3.16.5, which addresses an incompatible change within Liquibase itself (see #13031), you can now use relative paths along with an additional rootPath specification, which is required since Liquibase 4.0:

<!-- Specify the root path, e.g. a path in your Maven directory layout -->
<property>
  <key>rootPath</key>
  <value>${basedir}/src/main/resources</value>
</property>
    
<!-- Specify the relative path location of your XML, YAML, or JSON script. -->
<property>
  <key>scripts</key>
  <value>database.xml</value>
</property>

More longterm solution using an actual database

While the LiquibaseDatabase can help speed things up when your database is simple, as soon as you're using vendor specific features (stored procedures, data types, etc.), that approach isn't viable anymore. Running your migration on an actual PostgreSQL database, and then generating code from that would be much better. You could use testcontainers for that, as explained in this blog post.

  • Related