разность жидких фаз не работает - PullRequest
0 голосов
/ 15 января 2020

Я пытаюсь создать приложение Spring Boot 2.2.x (Java 13 ) с подходом Code-First с использованием Hibernate и Liquibase. Я хотел бы создать миграцию на основе различий между объектом сущностей и базой данных.

  • ОС - Win 10 и Mint 18
  • Сборка системы - Gradle 6.0.
  • База данных - Postgres SQL.

Я установил утилиты на базе жидкостей (3.8.2).

Мой сценарий gradle:

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

Когда я запускаю команду diff, основанную на сценарии gradle, например: . \ Gradlew.bat diff Я получаю следующий вывод:

> 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

Ответы [ 3 ]

1 голос
/ 16 января 2020

Трассировка стека указывает, что Liquibase 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)

Это указывает на то, что вы должны добавить jibrease-jibernate-jar к вашим зависимостям и раскомментировать строку referenceDriver в вашем скрипте gradle.

1 голос
/ 17 января 2020
  1. Я обновил liquibase (в Gradle) до версии 3.8.4
  2. Я добавил линии liquibaseRuntime с liquibase-hibernate и spring-data-jpa
  3. Я добавил в liquibase-hibernate и springp data-jpa classpath {} раздел сценария Gradle.

Весь сценарий Gradle:

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()
}
0 голосов
/ 15 января 2020

Не уверен, связано ли это с ошибками, с которыми вы сталкиваетесь, или нет, но Liquibase недавно опубликовала версию 3.8.4, которая исправляет некоторые ошибки Spring Boot с помощью Java 9+. https://www.liquibase.org/2019/12/liquibase-3-8-4-released.html

Я бы попробовал запустить это, чтобы посмотреть, решит ли это проблему для вас.

...