无法从liquibase gradle插件生成差异 [英] Unable to generate difference from liquibase gradle plugin

查看:236
本文介绍了无法从liquibase gradle插件生成差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在现有的SpringBoot项目中使用MYSQL数据库实现liquibase。我希望能够生成更改集,以指定实体更改时的差异。



我所做的:



我在 build.gradle 文件中添加了liquibase依赖项和gradle liquibase插件。进行域更改后,我运行了 gradle generateChangeLog 。该命令执行成功,但没有任何反应。



我在某处读到这个gradle插件只能用于内存h2数据库吗?真的吗?如果是,那么我应该使用什么替代方法自动生成更新日志。



我找不到一个基于SpringBoot gradle的示例,它使用MYSQL并且liquibase实现了自动更改生成功能。如果有人能够提供,这将是非常好的。

参考文献:

https://github.com/stevesaliman/liquibase-workshop



https://github.com/liquibase/liquibase-gradle-plugin

解决方案

解决方案是编写一个调用 liquibase diffChangeLog



在项目根目录下创建一个 liquibase.gradle 文件,添加liquibase-hibernate扩展并编写一个gradle任务,调用 liquibase diffChangeLog

 配置{
liquibase
}

依赖关系{
liquibase组:'org.liquibase.ext',名称:'liquibase-hibernate4',版本:3.5
}

//载入属性文件。
属性liquibaseProps = new Properties()
liquibaseProps.load(新的FileInputStream(src / main / resources / liquibase-task.properties))

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

任务liquibaseDiffChangelog(类型:JavaExec){
group =liquibase


classpath sourceSets.main.runtimeClasspath
classpath configurations.liquibase
main =liquibase.integration.commandline.Main

args--changeLogFile =+ liquibaseProps.getProperty('liquibase.changelog.path')+ buildTimestamp()+_ changelog.xml
args--referenceUrl = hibernate:spring:+ liquibaseProps.getProperty( 'liquibase.domain.package')+?dialect =+ applicationProps.getProperty('spring.jpa.properties.hibernate.dialect')
args--username =+ applicationProps.getProperty('spring。 datasource.username')
args--password =+ applicati onProps.getProperty('spring.datasource.password')
args--url =+ applicationProps.getProperty('spring.datasource.url')
args--driver = com.mysql。 jdbc.Driver
argsdiffChangeLog
}

def buildTimestamp(){
def date = new Date()
def formattedDate = date。格式('yyyyMMddHHmmss')
返回formattedDate
}

注意:使用属性文件将参数传递给liquibase命令,可以直接添加值,但这不是一个好习惯。

接下来,您需要在项目的中应用 liquibase.gradle build.gradle 文件。并添加liquibase依赖关系

  apply from:'liquibase.gradle'
//代码省略
依赖关系{
compile(group:'org.liquibase',name:'liquibase-core',version:3.4.2)
}

完成这一步后,liquibase将完全安装完毕。


现在可以使用 gradle liquibaseDiffChangeLog 生成
更新日志。



I'm trying to implement liquibase in an existing SpringBoot project with MYSQL database. I want to be able to generate changesets which specify the differences when an entity is changed.

What I've done:

I've added liquibase dependencies and the gradle liquibase plugin in my build.gradle file. After making a domain change, I've run gradle generateChangeLog. The command executes successfully but nothing happens.

I read somewhere that this gradle plugin works only for the inmemory h2 database? Is that true? If yes then what alternative should I use to generate changelogs automatically.

I could not find a working SpringBoot gradle based example which uses MYSQL and has liquibase implemented WITH automatic change generation ability. It would be great if someone could provide that.

References:

https://github.com/stevesaliman/liquibase-workshop

https://github.com/liquibase/liquibase-gradle-plugin

解决方案

The solutions is to write a gradle task which invokes liquibase diffChangeLog

Create a liquibase.gradle file in the project root directory, add liquibase-hibernate extension and write a gradle task that invokes the liquibase diffChangeLog command.

configurations {
  liquibase
}

dependencies {
  liquibase group: 'org.liquibase.ext', name: 'liquibase-hibernate4', version: 3.5
}

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

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

task liquibaseDiffChangelog(type: JavaExec) {
  group = "liquibase"


  classpath sourceSets.main.runtimeClasspath
  classpath configurations.liquibase
  main = "liquibase.integration.commandline.Main"

  args "--changeLogFile=" + liquibaseProps.getProperty('liquibase.changelog.path')+ buildTimestamp() +"_changelog.xml"
  args "--referenceUrl=hibernate:spring:" + liquibaseProps.getProperty('liquibase.domain.package') + "?dialect=" + applicationProps.getProperty('spring.jpa.properties.hibernate.dialect')
  args "--username=" + applicationProps.getProperty('spring.datasource.username')
  args "--password=" + applicationProps.getProperty('spring.datasource.password')
  args "--url=" + applicationProps.getProperty('spring.datasource.url')
  args "--driver=com.mysql.jdbc.Driver"
  args "diffChangeLog"
}

def buildTimestamp() {
  def date = new Date()
  def formattedDate = date.format('yyyyMMddHHmmss')
  return formattedDate
}

NOTE: I have used properties files to pass arguments to the liquibase command, you could add the values directly, but that would not be a good practice.

Next, you would need to apply the liquibase.gradle file from within the project's build.gradle file. and add the liquibase dependency

apply from: 'liquibase.gradle'
//code omitted
dependencies {
    compile (group: 'org.liquibase', name: 'liquibase-core', version: "3.4.2")
}

After this step liquibase would be setup completely.

You can now use gradle liquibaseDiffChangeLog to generate changelogs.

这篇关于无法从liquibase gradle插件生成差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆