liquibase gradle postgresql wrong driver

吃可爱长大的小学妹 提交于 2021-01-27 21:24:36

问题


Environment:

  • Spring boot (STS 3.9.1)
  • Gradle 2.13
  • Postgresql 9.6.5
  • Liquibase Gradle plugin (liquibase-gradle-plugin:1.2.4)

Scenario:

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')
}

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

gradle task dev update

Which should update the database

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

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


回答1:


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

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/


来源:https://stackoverflow.com/questions/46921580/liquibase-gradle-postgresql-wrong-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!