liquibase gradle postgresql错误的驱动程序 [英] liquibase gradle postgresql wrong driver

查看:72
本文介绍了liquibase gradle postgresql错误的驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 春季启动(STS 3.9.1)
  • 2.13级
  • PostgreSQL 9.6.5
  • Liquibase Gradle插件(liquibase-gradle-plugin:1.2.4)

我们有一个spring boot rest api,我们希望它具有一个CI进程,该进程会在进程的某个阶段更新数据库,为此,我们希望对其使用gradle

We have a spring boot rest api, we want it to have a CI process that updates the database at a stage of the process, for this we want to use gradle for it

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任务来执行此任务:

So we have a dev task created in order to execute this:

gradle task dev update

哪个应该更新数据库

如果我们允许该应用自动更新数据库,则效果很好,但是如果我们要使用taskt插件并使用gradle任务,则会收到错误消息

It works great if we allow the app to update the database automatically, but if we want to use the taskt plugin and use gradle tasks we are getting the error

    * 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插件有关.

So the problem seems to be related to the liquibase-gradle plug-in.

推荐答案

您的数据库url有点奇怪.缺少jdbc部分,可能缺少端口号.

Your db url looks kinda strange. Missing jdbc part and probably port number.

来自文档:驱动程序可识别以下形式的JDBC URL:

From documentation: the driver recognises JDBC URLs of the form:

jdbc:postgresql:database
jdbc:postgresql:/
jdbc:postgresql://host/database
jdbc:postgresql://host/
jdbc:postgresql://host:port/database
jdbc:postgresql://host:port/

这篇关于liquibase gradle postgresql错误的驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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