在执行 mvn clean compile liquibase 更新后,jOOQ 自动生成器不是 运行

jOOQ auto-generator is not running after liquibase update on doing mvn clean compile

我希望 jOOQ 根据我提供的 liquibase 模式 xml 文件自动生成代码(而不是基于数据库连接)。 如果我在 liquibase xml 文件中更改某些内容,更改会反映在数据库中,但我无法使用新的自动生成的代码。 我必须 运行 mvn clean compile 两次才能让 jOOQ 理解更改。

我的 pom.xml 的生成器部分如下所示。请帮助:

<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>

您的问题是关于

通过在 LiquibaseDatabase 之外添加 PostgresDatabase,您只需覆盖 <name/> 元素的 LiquibaseDatabase 配置。您不能指定其中的多个。

您试图解决的问题

请查看 jOOQ LiquibaseDatabase 的文档。它提到 scripts 属性 应该描述迁移文件的 classpath 位置,而不是相对路径位置,例如

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

(注意开头的斜杠)。从 jOOQ 3.16.5 开始,它解决了 Liquibase 本身内部的不兼容更改(参见 #13031),您现在可以使用相对路径以及额外的 rootPath 规范,这是自 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>

使用实际数据库的更长期解决方案

虽然 LiquibaseDatabase 可以在您的数据库很简单时帮助加快速度,但一旦您使用供应商特定的功能(存储过程、数据类型等),这种方法就不可行了了。 运行 在实际的 PostgreSQL 数据库上迁移,然后从中生成代码会好得多。 You could use testcontainers for that, as explained in this blog post.