Charles Ju
Charles Ju

Reputation: 1259

liquibase gradle plugin can not find org.postgresql.Driver

I am trying to use liquibase-gradle-plugin to generate database diffs between a database and Springboot Entities. However, I always got the error saying

liquibase.exception.LiquibaseException: Unexpected error running Liquibase: java.lang.RuntimeException: Cannot find database driver: class org.postgresql.Driver

I put classpath depencies in the buildscripts block according to some google result. But it does not help. Below is my build.gradle

buildscript {
    ext {
        springBootVersion = '1.5.6.RELEASE'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/milestone" }
        maven {
            url "https://plugins.gradle.org/m2/"
          }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath('org.postgresql:postgresql:9.4.1212')
    }
}

//When the liquibase plugin is applied, it creates a Gradle task for each command supported by Liquibase.
plugins {
    id 'org.liquibase.gradle' version '1.2.4'
}

apply from: 'liquibase.gradle'

liquibase {
    activities {
      diffMain {
        url gradle.ext.url
        username gradle.ext.username
        password gradle.ext.password
        referenceUrl gradle.ext.referenceUrl
        driver org.postgresql.Driver
      }
    }
    runList = 'diffMain'
}

Upvotes: 1

Views: 2136

Answers (1)

Torino
Torino

Reputation: 452

You might want to define driver location in activities field of liquibase configuration with classpath property:

liquibase {
    activities {
      diffMain {
        url gradle.ext.url
        username gradle.ext.username
        password gradle.ext.password
        referenceUrl gradle.ext.referenceUrl
        driver org.postgresql.Driver

        /////
        classpath "/driver-location/postgresql-42.2.19.jar"
        /////
      }
    }
    runList = 'diffMain'
}

But more common and right approach is to add driver into liquibase runtime environment:

dependencies {
    liquibaseRuntime "org.postgresql:postgresql:42.2.24"
}

Upvotes: 4

Related Questions