解决方案是编写gradle任务来调用
liquibase diffChangeLog
liquibase.gradle在项目根目录中创建一个文件,添加liquibase-
hibernate扩展并编写一个gradle任务来调用该
liquibase diffChangeLog命令。
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}注意:我已经使用属性文件将参数传递给liquibase命令,您可以直接添加值,但这不是一个好习惯。
接下来,您需要
liquibase.gradle从项目
build.gradle文件中应用文件。并添加liquibase依赖
apply from: 'liquibase.gradle'//pre omitteddependencies { compile (group: 'org.liquibase', name: 'liquibase-core', version: "3.4.2")}此步骤之后,将完全设置liquibase。
现在,您可以
gradle liquibaseDiffChangeLog用来生成变更日志。



