Reputation: 2779
I am attempting to make Spring Boot 2.2.x application (Java 13) with Code-First approach using Hibernate and Liquibase. I would like to generate migrations base on difference between Entities object and database.
I installed liquibase utilities (3.8.2).
My gradle script:
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'net.ltgt.gradle:gradle-apt-plugin:0.18'
classpath 'org.postgresql:postgresql:42.2.9'
classpath 'org.liquibase:liquibase-core:3.8.2'
classpath "org.liquibase:liquibase-gradle-plugin:2.0.2"
}
}
plugins {
id 'org.springframework.boot' version '2.2.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'org.liquibase.gradle' version '2.0.2'
id 'java'
}
group = 'com.goodt.drive'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '13'
targetCompatibility = '13'
diff.dependsOn compileJava
diffChangeLog.dependsOn compileJava
generateChangelog.dependsOn compileJava
dependencies {
liquibaseRuntime 'org.liquibase:liquibase-core:3.8.2'
liquibaseRuntime "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
liquibaseRuntime 'org.springframework.boot:spring-boot:2.2.1.RELEASE'
liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:2.0.1'
liquibaseRuntime 'org.postgresql:postgresql:42.2.9'
liquibaseRuntime 'org.hibernate:hibernate-core:5.4.10.Final'
liquibaseRuntime 'ch.qos.logback:logback-core:1.2.3'
liquibaseRuntime 'ch.qos.logback:logback-classic:1.2.3'
liquibaseRuntime sourceSets.main.output
}
def dbChangeLog = "$projectDir/src/main/resources/db/changelog/changelog.xml"
def generatedChangeLog = "$projectDir/src/main/resources/db/changelog/generated_changelog.xml"
liquibase {
activities {
main {
changeLogFile dbChangeLog
outputFile generatedChangeLog
driver "org.postgresql.Driver"
classpath "$projectDir/lib/postgresql-42.2.9.jar"
url "jdbc:postgresql://localhost:5432/webportal"
username "developer"
password "123"
referenceUrl "hibernate:spring:com.wissance.webportal.application.model.entities?dialect=org.hibernate.dialect.PostgreSQL94Dialect"
//referenceDriver 'liquibase.ext.hibernate.database.connection.HibernateDriver'
}
}
}
When i am runnung liquibase diff command from gradle script like this: .\gradlew.bat diff i am getting following output:
> Task :diff
liquibase-plugin: Running the 'main' activity...
12:48:14.372 INFO [liquibase.integration.commandline.Main]: Starting Liquibase at ёЁ, 15 эт. 2020 12:48:14 YEKT (version 3.8.2 #26 built at Tue Nov 26 04:53:39 UTC 2019)
12:48:15.323 INFO [liquibase.integration.commandline.Main]: No Liquibase Pro license key supplied. Please set liquibaseProLicenseKey on command line or in liquibase.properties to use Liquibase Pro features.
12:48:15.325 INFO [liquibase.integration.commandline.Main]: Liquibase Community 3.8.2 by Datical
12:48:15.614 ERROR [liquibase.integration.commandline.Main]: Unexpected error running Liquibase: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.wissance.webportal.application.model.entities?dialect=org.hibernate.dialect.PostgreSQL94Dialect)
liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.wissance.webportal.application.model.entities?dialect=org.hibernate.dialect.PostgreSQL94Dialect)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:132)
at liquibase.integration.commandline.Main.createReferenceDatabaseFromCommandParams(Main.java:1604)
at liquibase.integration.commandline.Main.doMigration(Main.java:1200)
at liquibase.integration.commandline.Main.run(Main.java:229)
at liquibase.integration.commandline.Main.main(Main.java:143)
Caused by: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.wissance.webportal.application.model.entities?dialect=org.hibernate.dialect.PostgreSQL94Dialect)
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:263)
at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:149)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:97)
... 4 common frames omitted
Caused by: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.wissance.webportal.application.model.entities?dialect=org.hibernate.dialect.PostgreSQL94Dialect)
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:200)
... 6 common frames omitted
Upvotes: 2
Views: 4802
Reputation: 2779
One more addition, i write an article about how to use liquibase you could find it here: https://m-ushakov.medium.com/code-first-with-spring-boot-hibernate-and-liquibase-48f5c9998d95
Whole Gradle script:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'net.ltgt.gradle:gradle-apt-plugin:0.18'
classpath 'org.postgresql:postgresql:42.2.9'
classpath 'org.liquibase.ext:liquibase-hibernate5:3.8'
classpath 'org.liquibase:liquibase-core:3.8.4'
classpath 'org.liquibase:liquibase-gradle-plugin:2.0.2'
classpath 'org.springframework.data:spring-data-jpa:2.2.1.RELEASE'
}
}
plugins {
id 'org.springframework.boot' version '2.2.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'org.liquibase.gradle' version '2.0.2'
id 'java'
}
group = 'com.wissance.webportal'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '13'
targetCompatibility = '13'
ext {
set('springCloudVersion', "Hoxton.RC2")
set('queryDslVersion', "4.1.3")
set('swaggerVersion', "2.9.2")
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
diff.dependsOn compileJava
diffChangeLog.dependsOn compileJava
generateChangelog.dependsOn compileJava
dependencies {
// spring boot
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-hateoas'
compile 'org.springframework.boot:spring-boot-starter-web'
// spring cloud
//implementation 'org.springframework.cloud:spring-cloud-starter-config'
//implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
// JAX-B dependencies for JDK 9+
implementation "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
implementation "org.glassfish.jaxb:jaxb-runtime:2.3.2"
// other
compile 'org.postgresql:postgresql:42.2.1'
compile 'com.h2database:h2'
compile 'org.hibernate:hibernate-core:5.4.10.Final'
compileOnly 'org.projectlombok:lombok'
//runtimeOnly 'org.postgresql:postgresql'
runtime 'javax.xml.bind:jaxb-api'
//runtime 'org.liquibase:liquibase-core'
liquibaseRuntime 'org.liquibase:liquibase-core:3.8.4'
liquibaseRuntime "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
liquibaseRuntime 'org.springframework.boot:spring-boot:2.2.1.RELEASE'
liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:2.0.1'
liquibaseRuntime 'org.postgresql:postgresql:42.2.9'
liquibaseRuntime 'org.springframework.data:spring-data-jpa:2.2.1.RELEASE'
liquibaseRuntime 'org.hibernate:hibernate-core:5.4.10.Final'
liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:3.8'
liquibaseRuntime 'ch.qos.logback:logback-core:1.2.3'
liquibaseRuntime 'ch.qos.logback:logback-classic:1.2.3'
liquibaseRuntime sourceSets.main.output
// TESTS
//testImplementation('org.springframework.boot:spring-boot-starter-test') {
// exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
//}
testCompile('org.junit.jupiter:junit-jupiter-engine:5.2.0')
// QueryDsl
compile "com.querydsl:querydsl-core:${queryDslVersion}"
compile "com.querydsl:querydsl-jpa:${queryDslVersion}"
// Swagger
compile "io.springfox:springfox-swagger2:${swaggerVersion}"
compile "io.springfox:springfox-swagger-ui:${swaggerVersion}"
annotationProcessor (
"org.projectlombok:lombok",
"com.querydsl:querydsl-apt:${queryDslVersion}:jpa",
"org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final",
"javax.annotation:javax.annotation-api:1.3.2"
)
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
def dbChangeLog = "$projectDir/src/main/resources/db/changelog/changelog.xml"
def generatedChangeLog = "$projectDir/src/main/resources/db/changelog/generated_changelog.xml"
/*task copyToLib(type: Copy) {
into "$buildDir/output/libs"
from configurations.runtime
}*/
liquibase {
activities {
main {
changeLogFile dbChangeLog
outputFile generatedChangeLog
driver "org.postgresql.Driver"
// classpath "$projectDir/lib/postgresql-42.2.9.jar"
url "jdbc:postgresql://localhost:5432/webportal
password "123"
referenceUrl "hibernate:spring:com.wissance.webportal.application.model.entities?dialect=org.hibernate.dialect.PostgreSQL94Dialect"
referenceDriver 'liquibase.ext.hibernate.database.connection.HibernateDriver'
}
}
}
jar {
enabled = true
manifest {
attributes 'Main-Class': 'com.wissance.webportal.Application'
}
}
test {
useJUnitPlatform()
}
Upvotes: 2
Reputation: 9016
The stack trace indicates that Liquibase Cannot find database driver
and Driver class was not specified and could not be determined from the url (hibernate:spring:com.wissance.webportal.application.model.entities?dialect=org.hibernate.dialect.PostgreSQL94Dialect)
This indicates that you should add the liquibase-hibernate jar to your dependencies and uncomment the referenceDriver
line in your gradle script.
Upvotes: 2
Reputation: 1
Not sure if it's related to the errors you are experiencing or not, but Liquibase recently posted a 3.8.4 version that corrects some Spring Boot errors with Java 9+. https://www.liquibase.org/2019/12/liquibase-3-8-4-released.html
I'd try running that to see if it resolves the issue for you.
Upvotes: 0