我试图运行liquibase脚本来创建Posgresql DB +模式。
这里有一些liquibase .groovy配置和脚本以及build.gradle。
的build.gradle
apply plugin: 'liquibase'
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'org.liquibase:liquibase-gradle-plugin:1.2.0'
classpath "org.postgresql:postgresql:${postgreJdbcDriverVersion}"
}
}
sourceSets {
main {
java {
srcDir 'src/main/liquibase'
}
}
}
liquibase {
activities {
main {
File propsFile = new File("src/main/resources/database.properties")
Properties properties = new Properties()
properties.load(new FileInputStream(propsFile))
changeLogFile 'src/main/liquibase/com/freemmy/sample/spring/acl/sample/db/main-changelog.groovy'
url "${dbUrl}"
username "${dbUsername}"
password "${dbPassword}"
}
}
runList = 'main'
}
例如,我在 main-changelog.groovy 中有以下变更集:
changeSet(id: '2016-12-10-a', author: 'Dzmitry Dziokin', runInTransaction: false, runAlways: true, runOnChange: true, failOnError: false, dbms: 'postgresql') {
comment('Create the database role/login')
// Ok if the role exists
preConditions(onFail: 'CONTINUE', onFailMessage: 'Role already exists, continue') {
sqlCheck(expectedResult: '0')
{ "select count(*) from pg_roles where rolname= '${dbUsername}'" }
}
sql(stripComments: true, splitStatements: false, endDelimiter: ';') {
"CREATE ROLE ${dbUsername} LOGIN PASSWORD '${dbPassword}'"
}
}
我有属性dbUsername
和dbPassword
。
但是当我跑步时,gradlew status
我看到以下内容:
Execution failed for task ':spring-acl-sample-db:status'.
liquibase.exception.LiquibaseException:运行Liquibase时出现意外错误:没有这样的属性:类的dbUsername:org.liquibase.groovy.delegate.PreconditionDelegate
我问谷歌,但我还没有找到任何解决方案或建议。
有人知道发生了什么吗?
答案 0 :(得分:0)
我假设您的属性文件中定义了dbUsername和dbPassword。
您必须在gradle脚本中定义dbUsername和dbPassword:
def dbUsername = properties.getProperty("dbUsername")
def dbPassword = properties.getProperty("dbPassword")
答案 1 :(得分:0)
您应该在插值中使用properties
前缀。
url "${properties.dbUrl}"
username "${properties.dbUsername}"
password "${properties.dbPassword}"