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

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

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:

  1. apply plugin: 'org.springframework.boot'
  2. apply plugin: 'org.liquibase.gradle'
  3. dependencies {
  4. liquibaseRuntime 'org.liquibase:liquibase-core:4.22.0'
  5. liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:3.0.0'
  6. liquibaseRuntime 'org.postgresql:postgresql:42.3.8'
  7. liquibaseRuntime 'info.picocli:picocli:4.7.3'
  8. liquibaseRuntime 'org.yaml:snakeyaml:2.0'
  9. liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:4.22.0'
  10. ...
  11. }
  12. liquibase {
  13. activities {
  14. main {
  15. classpath 'src/main/resources'
  16. changeLogFile 'src/main/resources/db/changelog/db.changelog-master.yaml'
  17. url 'jdbc:postgresql://localhost:5432/dbname'
  18. username 'postgres'
  19. password 'postgres'
  20. driver 'org.postgresql.Driver'
  21. 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'
  22. }
  23. }
  24. }

and plugins:

  1. plugins {
  2. id 'java'
  3. id 'java-library'
  4. id 'application'
  5. id 'org.springframework.boot' version "$springBootVersion"
  6. id 'org.liquibase.gradle' version '2.2.0'
  7. }

db.changelog-master.yaml file:

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

My first.groovy file:

  1. package db.changelog.changes
  2. databaseChangeLog() {
  3. changeSet(id: 'create-schema', author: 'testowner') {
  4. sql(stripComments: true, splitStatements: false, endDelimiter: ';') {
  5. "CREATE TABLE public.test_entity (" +
  6. "id bigserial NOT NULL);"
  7. }
  8. }
  9. }

My file structure:

  1. src
  2. main
  3. resources
  4. db
  5. changelog
  6. changes
  7. first.groovy
  8. db.changelog-master.yaml

Java Sdk:

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

java-config.gradle file:

  1. apply plugin: 'java'
  2. sourceCompatibility = JavaVersion.VERSION_17
  3. targetCompatibility = JavaVersion.VERSION_17

And error liquibase update gives:

  1. 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 参数。

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

一旦添加了 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

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

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:

确定