Liquibase找不到liquibase.changelog.ChangeSet的构造函数。

huangapple go评论65阅读模式
英文:

Liquibase can not find constructor for liquibase.changelog.ChangeSet

问题

这是您的Gradle多模块Spring Boot项目的一些信息,以及出现的错误。如果您需要进一步的帮助或有特定问题,请告诉我。

英文:

I have a gradle multi module spring boot project.

My build.gradle file:

apply plugin: 'org.springframework.boot'
apply plugin: 'org.liquibase.gradle'

dependencies {
    liquibaseRuntime 'org.liquibase:liquibase-core:4.22.0'
    liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:3.0.0'
    liquibaseRuntime 'org.postgresql:postgresql:42.3.8'
    liquibaseRuntime 'info.picocli:picocli:4.7.3'
    liquibaseRuntime 'org.yaml:snakeyaml:2.0'
    liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:4.22.0'
    ...

    }

liquibase {
    activities {
        main {
            classpath 'src/main/resources'
            changeLogFile 'src/main/resources/db/changelog/db.changelog-master.yaml'
            url 'jdbc:postgresql://localhost:5432/dbname'
            username 'postgres'
            password 'postgres'
            driver 'org.postgresql.Driver'
            referenceUrl     'hibernate:spring:com.test.test?    dialect=org.hibernate.dialect.PostgreSQL95Dialect&hibernate.physical_naming_strategy=org.    springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_na    ming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy'
        }
    }
}

and plugins:

plugins {
    id 'java'
    id 'java-library'
    id 'application'
    id 'org.springframework.boot' version "$springBootVersion"
    id 'org.liquibase.gradle' version '2.2.0'
}

db.changelog-master.yaml file:

databaseChangeLog:
  - include:
      file: db/changelog/changes/first.groovy

My first.groovy file:

package db.changelog.changes

databaseChangeLog() {
    changeSet(id: 'create-schema', author: 'testowner') {
        sql(stripComments: true, splitStatements: false, endDelimiter: ';') {
            "CREATE TABLE public.test_entity (" +
                    "id bigserial NOT NULL);" 
        }
    }
}

My file structure:

src
 main
  resources
   db
    changelog
     changes
      first.groovy
     db.changelog-master.yaml

Java Sdk:

java 17.0.2 2022-01-18 LTS
Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)

java-config.gradle file:

apply plugin: 'java'

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

And error liquibase update gives:

Caused by: liquibase.exception.ChangeLogParseException: Error parsing src/main/resources/db/changelog/db.changelog-master.yaml : Could not find matching constructor for: liquibase.changelog.ChangeSet(java.lang.String, java.lang.String, java.lang.Boolean, java.lang.Boolean, java.lang.String, null, null, null, java.lang.Boolean, null, liquibase.changelog.DatabaseChangeLog)

答案1

得分: 1

错误是由Liquibase配置问题引起的。ChangeSet 类有一个构造函数,接受11个参数,但 db.changelog-master.yaml 文件只提供了10个。缺少的参数是 contexts 参数,它是应用于变更集的上下文列表。

要修复错误,请在 db.changelog-master.yaml 中的 ChangeSet 中添加 contexts 参数。

changeSet(id: 'create-schema', author: 'testowner', contexts: ['test']) {
    sql(stripComments: true, splitStatements: false, endDelimiter: ';') {
        "CREATE TABLE public.test_entity (" +
                "id bigserial NOT NULL);"
    }
}

一旦添加了 contexts 参数,liquibase update 命令应该成功执行。

英文:

The error is caused by a Liquibase configuration issue. The ChangeSet class has a constructor that takes 11 parameters, but the db.changelog-master.yaml file is only providing 10. The missing parameter is the contexts parameter, which is a list of contexts that the change set should be applied to.
To fix the error, add the contexts parameter to the ChangeSet in the db.changelog-master.yaml

changeSet(id: 'create-schema', author: 'testowner', contexts: ['test']) {
    sql(stripComments: true, splitStatements: false, endDelimiter: ';') {
        "CREATE TABLE public.test_entity (" +
                "id bigserial NOT NULL);" 
    }
}

Once you have added the contexts parameter, the liquibase update command should succeed.

huangapple
  • 本文由 发表于 2023年5月14日 06:13:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76245081.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定