[英]liquibase gradle postgresql wrong driver
我們有一個spring boot rest api,我們希望它有一個CI進程來在進程的某個階段更新數據庫,為此,我們想使用gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('org.springframework.boot:spring-boot-gradle-plugin:1.5.7.RELEASE')
// tag::build[]
classpath('se.transmode.gradle:gradle-docker:1.2')
// end::build[]
classpath('org.liquibase:liquibase-gradle-plugin:1.2.4')
classpath('org.postgresql:postgresql:42.1.4')
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
// tag::plugin[]
apply plugin: 'docker'
// end::plugin[]
apply plugin: 'org.liquibase.gradle'
bootRun {
systemProperty 'spring.profiles.active', System.properties['spring.profiles.active']
}
def changeLog = "$projectDir/src/main/resources/db/db.changelog-master.yaml"
task('dev') << {
println 'executing dev'
liquibase{
activities {
main {
changeLogFile changeLog
url 'postgresql://localhost/mydatabase'
username 'postgres'
password 'mysecret'
driver 'org.postgresql.Driver'
}
}
}
}
jar {
baseName = 'applicationTestLiquibasegradle'
version = '0.0.3'
}
// This is used as the docker image prefix (org)
group = 'com.cropmetrics'
version = '0.0.3'
sourceCompatibility = 1.8
// tag::task[]
task buildDocker(type: Docker, dependsOn: build) {
applicationName = jar.baseName
dockerfile = file('Dockerfile')
doFirst {
copy {
from jar
into "${stageDir}/target"
}
}
}
// end::task[]
repositories {
mavenCentral()
}
dependencies {
compileOnly('org.projectlombok:lombok:1.16.18')
compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
// JPA Data (We are going to use Repositories, Entities, Hibernate, etc...)
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile('org.liquibase:liquibase-core')
compile('org.postgresql:postgresql:42.1.4.jre7')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
因此,我們創建了一個dev任務來執行此任務:
gradle task dev update
哪個應該更新數據庫
如果我們允許應用程序自動更新數據庫,則效果很好,但是如果我們要使用taskt插件並使用gradle任務,則會收到錯誤消息
* What went wrong:
Execution failed for task ':update'.
> liquibase.exception.LiquibaseException: Unexpected error running Liquibase: liquibase.exception.DatabaseException: Connection could not be created to postgresql://localhost/cropmetricsdatabase with driver org.postgresql.Driver. Possibly the wrong driver for the given database URL
因此,問題似乎與liquibase-gradle插件有關。
您的數據庫網址看起來有些奇怪。 缺少jdbc部分,可能缺少端口號。
根據文檔 :驅動程序可以識別以下形式的JDBC URL:
jdbc:postgresql:database
jdbc:postgresql:/
jdbc:postgresql://host/database
jdbc:postgresql://host/
jdbc:postgresql://host:port/database
jdbc:postgresql://host:port/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.