【问题标题】:Gradle Liquibase change log file could not be found找不到 Gradle Liquibase 更改日志文件
【发布时间】:2015-01-27 01:45:01
【问题描述】:

在我们的项目中使用 gradle-liquibase 插件解决了所有依赖项。

按照 Gradle liquibase 插件的建议,我有以下 liquibase 任务:

liquibase {
   activities {
   main {      
      changeLogFile 'src/main/resources/db/dbchangelog-master.xml'
      url 'jdbc:mysql://localhost:3306/test'
      username 'XXX'
      password 'XXX'
     } 
  }
 runList = 'main'
}

虽然日志文件位于项目类路径目录(src/main/resources/)中,但 liquibase 无法识别 changeLogFile 时遇到问题

错误:

Caused by: liquibase.exception.ChangeLogParseException:
src/main/resources/dbchangelog/db.changelog-master.xml does not exist

关于我应该如何解决这个类路径相关问题的任何帮助?

【问题讨论】:

    标签: gradle liquibase build.gradle


    【解决方案1】:

    只需在 src 目录所在的位置添加一个类路径参数

    liquibase {
       activities {
       main {      
          changeLogFile 'src/main/resources/db/dbchangelog-master.xml'
          url 'jdbc:mysql://localhost:3306/test'
          username 'XXX'
          password 'XXX'
          classpath "$rootDir"
         } 
      }
     runList = 'main'
    }
    

    【讨论】:

      【解决方案2】:

      我在使用 gradle liquibase 插件版本 1.0.0 时遇到了同样的问题,并找到了解决方法...在您的示例中,它会是这样的:

      liquibase {
         activities {
         main {      
            changeLogFile "${this.rootDir}/src/main/resources/db/dbchangelog-master.xml"
            url 'jdbc:mysql://localhost:3306/test'
            username 'XXX'
            password 'XXX'
           } 
        }
       runList = 'main'
      }
      

      当您从 eclipse 运行 gradle 任务时 - 它确实会尝试在 eclipse 本身的根目录中查找更改日志文件...

      【讨论】:

      • 如果只有一个 liquibase 文件,您的解决方法很好。但是我有一个包含多个包含文件的 master.xml 文件:<include file="src/main/resources/db/dbchangelog-1.0.xml" /> 这仍然给了我相同的Error thrown as a SAXException: src/main/resources/db/dbchangelog-1.0.xml does not exist
      • @PondicherryFellow 嗯...应该可以工作...您的主 xml 中是否包含 relativeToChangelogFile="true" 属性?喜欢:<include file="common/triggers-changelog.xml" relativeToChangelogFile="true"/>
      【解决方案3】:

      当前目录实际上是否在您的类路径中?通常,您的类路径配置为包含“目标”输出目录,并且可能包含“src/main/resources”作为另一个类路径根目录。

      如果你使用changeLogFile 'db/dbchangelog-master.xml',它可以工作吗?

      【讨论】:

      • 我从 Eclipse 运行 gradle update 命令。但是,我的项目与 Eclipse 工作区(c:/workspace)位于不同的目录(c:/myproject)中。 gradle update 在项目目录中的 Eclipse 之外的命令行中使用时可以正常工作。
      • Liquibase 设置类路径的方式会有所不同,具体取决于您运行 Liquibase 的方式。默认情况下,命令行使用当前目录作为类路径以及您使用 --classpath 参数列出的任何其他内容。 Gradle 可能只是使用“src/main/resources”作为类路径并且不包含项目目录。你应该做的是使用“db/dbchangelog-master.xml”作为gradle中的changeLogFile,当你从命令行运行时包括--classpath=src/main/rsources参数
      • 但这在 Eclipse 中不起作用....Caused by: liquibase.exception.ChangeLogParseException: db/changelog-master.xml does not exist
      • 您可能需要为类路径属性使用绝对路径,例如 --classpath=c:\myproject\src\main\resources
      猜你喜欢
      • 2020-02-12
      • 2018-12-14
      • 2021-10-10
      • 1970-01-01
      • 2020-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-23
      相关资源
      最近更新 更多