Liquibase 4.0 无法在 jar 中启动

Liquibase 4.0 fails to start in jar

我使用 Spring 2.3.3 和 Liquibase 4.0.0。 它在 运行 gradlew bootRun 时工作正常,但是当我 运行 编译 jar 时,我收到大量消息,例如:

    2020-09-11 17:40:33.267  WARN 1 --- [           main] liquibase.integration                    : Cannot create filesystem for url jar:file:/app.jar!/BOOT-INF/lib/spring-aspects-5.2.8.RELEASE.jar!/: null

java.nio.file.FileSystemNotFoundException: null

...

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfigurati
on.class]: Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException: Error parsing classpath:/db/changelog/db.changelog-master.yaml

Liqubase gradle 配置和 运行 时间库:

configurations {
liquibaseRuntime.extendsFrom runtime

compileOnly {
    extendsFrom annotationProcessor
}

Properties liquibaseProps = new Properties()
liquibaseProps.load(new FileInputStream("src/main/resources/liquibase.properties"))

Properties applicationProps = new Properties()
applicationProps.load(new FileInputStream("src/main/resources/application.properties"))

liquibase {

    activities {

        main {
            referenceUrl 'hibernate:spring:' + liquibaseProps.getProperty('liquibase.domain.package') + '?dialect=' + applicationProps.getProperty('spring.jpa.database-platform') + '&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy'
            driver applicationProps.getProperty('spring.datasource.driver-class-name')
            changeLogFile liquibaseProps.getProperty('liquibase.changelog.path') + migrationName() + '.yaml'
            url applicationProps.getProperty('spring.datasource.url')
            username applicationProps.getProperty('spring.datasource.username')
            password applicationProps.getProperty('spring.datasource.password')
        }
    }
}
}

运行时间:

liquibaseRuntime 'org.liquibase:liquibase-core:4.0.0'
liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:2.1.2'
liquibaseRuntime 'org.postgresql:postgresql'

liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:4.0.0'
liquibaseRuntime sourceSets.main.output

liquibaseRuntime "ch.qos.logback:logback-core"
liquibaseRuntime "ch.qos.logback:logback-classic"
liquibaseRuntime 'org.yaml:snakeyaml'
liquibaseRuntime group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'

liquibaseRuntime 'org.springframework.boot:spring-boot-starter-data-jpa'
liquibaseRuntime 'org.springframework.boot:spring-boot-starter-security'
liquibaseRuntime 'org.springframework.boot:spring-boot-starter-web'

liquibase.properties:

liquibase.changelog.path="classpath:src/main/resources/db/changelog/changes/"
liquibase.domain.package=ru.example.entities

应用配置 application.properties

spring.application.name = "Example"
application.description = "Example"
application.version = 1.0


spring.jpa.database-platform = org.hibernate.dialect.PostgreSQL10Dialect
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.hibernate.naming.implicit-strategy = org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl

spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql:localhost:5432/test
spring.datasource.username=postgres
spring.datasource.password=qwerty

我该如何解决?

更新:

已更新 resources/db/changelog/db.changelog-master.yaml:

databaseChangeLog:
  - includeAll:
      path: classpath:db/changelog/changes/

在 gradle 中更新了 liquibase 配置:

    liquibase {
        activities {
            main {
                classpath "$projectDir/src/main/resources/db/changelog"
...

添加到 application.properties: spring.liquibase.change-log=classpath:db/changelog/db.changelog-master.yaml

现在我仍然收到有关未找到 jar 依赖项的警告:

liquibase.integration                    : Cannot create filesystem for url jar:file:/app.jar!/BOOT-INF/lib/spring-aspects-5.2.8.RELEASE.jar!/: null

java.nio.file.FileSystemNotFoundException: null
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:172) ~[jdk.zipfs:na]

仍然没有找到嵌入的变更集:

 Could not find directory or directory was empty for includeAll 'db/changelog/changes/'

如果将 includeAll 替换为显式声明,则会修复问题:

databaseChangeLog:
  - include:
      file: changes/20200829022849_default.yaml
      relativeToChangelogFile: true

更新 2 这是存储库 https://github.com/dekar91/liquibase_ex 上的 link 我像这样构建并启动应用程序:

./gradleew bootJar
java -jar example-0.0.1-SNAPSHOT.jar

从您的配置来看,liquibase 似乎正在调整其默认设置,即 classpath:/db/changelog/db.changelog-master.yaml

所以添加到您的 application.properties 属性:

spring.liquibase.change-log=classpath:db/changelog/changes/<filename> - 请注意在此处添加文件名,以便它能够选择主要更新日志。

这是一个已提交的 liquibase 4.0.0 问题 https://github.com/liquibase/liquibase/issues/1276 Liquibase 3.10.2 工作正常。