我添加了一个gradle任务,用于迁移liquibase数据库,如下所示
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.liquibase:liquibase-core:4.4.3'
classpath "org.liquibase:liquibase-gradle-plugin:2.0.4"
classpath 'mysql:mysql-connector-java:5.1.13'
}
}
plugins {
id 'java'
id 'org.liquibase.gradle' version '2.0.4'
}
task dbmigrate {
doLast {
println "executing dev"
liquibase {
activities {
schema1 {
changeLogFile "$projectDir/src/main/resources/db/migrations.xml"
url 'jdbc:mysql://localhost:3306/bmw?zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8&serverTimezone=UTC'
username 'root'
password 'root'
driver 'com.mysql.jdbc.Driver'
}
schema2 {
changeLogFile '$projectDir/src/main/resources/db/migrations.xml'
url 'jdbc:mysql://localhost:3306/vw?zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8&serverTimezone=UTC'
username 'root'
password 'root'
driver 'com.mysql.jdbc.Driver'
}
}
runList = 'schema1, schema2'
}
}
}
build.dependsOn dbmigrate
当我运行gradlew build
或gradlew task dbmigrate
时,它打印出成功的字样"执行开发"。但是,当我检查dbs时,没有应用任何表模式更改。
任何想法?谢谢。
似乎有一些东西在你的build.gradle
缺失。我尝试执行命令./gradlew task dbmigrate update
,所以使用额外的update
命令。这给了我一些错误,比如Liquibase没有作为运行时依赖项。
我将此添加到您的构建文件中,然后当我运行./gradlew task dbmigrate update
时,它为我工作:
repositories {
mavenCentral()
}
dependencies {
liquibaseRuntime("org.liquibase:liquibase-core:4.4.3")
liquibaseRuntime("mysql:mysql-connector-java:5.1.13")
}