I've been trying to get the gradle plugin for liquibase+hibernate working based on several tutorials I have found online, and whenever I try generate the diff, I keep getting the following exception:
Driver class was not specified and could not be determined from the url (hibernate:spring:com.project.database.dto?dialect=org.hibernate.dialect.PostgreSQLDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy)
The path: "hibernate:spring:com.project.database.dto" represents the package where all my Hibernate Entities are.
Based on the documentation found here, https://docs.liquibase.com/commands/inspection/diff.html, it seems to be expecting something like
jdbc:postgres://localhost...
However, when I do that, the diff command works without any errors, but that is incorrect, as it appears to not pick up any changes I made to any of the entities. Based on several tutorials (or for example, this Stack over flow question here: "Cannot find database driver: Driver class was not specified and could not be determined from the url" error on using liquibase-hibernate plugin), it does seem like the "hibernate:spring:..." referenceUrl is needed).
This is my gradle file:
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.5'
id 'io.spring.dependency-management' version '1.1.0'
id 'org.liquibase.gradle' version '2.2.0'
}
group 'com.project'
version '1.0-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
//spring
//db--------------------------------------------------------------------
// https://mvnrepository.com/artifact/com.h2database/h2
testImplementation group: 'com.h2database', name: 'h2', version: '1.3.148'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// https://mvnrepository.com/artifact/org.postgresql/postgresql
implementation group: 'org.postgresql', name: 'postgresql', version: '42.6.0'
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.33'
//db migration ----------------------------------------------------------
// https://mvnrepository.com/artifact/org.liquibase/liquibase-core
//Liquibase
implementation group: 'org.liquibase', name: 'liquibase-core', version: '4.21.1'
liquibaseRuntime 'org.springframework.boot:spring-boot-starter-test'
liquibaseRuntime 'org.springframework.boot:spring-boot-starter-data-jpa'
liquibaseRuntime 'org.liquibase:liquibase-core:4.16.1'
liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:3.0.2'
liquibaseRuntime 'info.picocli:picocli:4.6.1'
liquibaseRuntime group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
liquibaseRuntime("ch.qos.logback:logback-core:1.2.3")
liquibaseRuntime("ch.qos.logback:logback-classic:1.2.3")
liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:3.6'
liquibaseRuntime group: 'org.postgresql', name: 'postgresql', version: '42.6.0'
liquibaseRuntime sourceSets.main.output
//--------------------------------------------------------------------
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
//unit test
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
liquibase {
activities {
main {
changelogFile "src/main/resources/db/changelog/db.changelog-master.yaml"
url "jdbc:postgresql://localhost:5432/db"
username "user"
password "pass"
driver "org.postgresql.Driver"
referenceUrl "hibernate:spring:com.project.database.dto?dialect=org.hibernate.dialect.PostgreSQLDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy"
}
}
}