liquibase / liquibase-gradle-plugin

A Gradle plugin for Liquibase
Other
197 stars 57 forks source link

Unable to run diffChangeLog with spring boot with java 11 #54

Closed jozefmorvay closed 5 years ago

jozefmorvay commented 5 years ago

Hello. As instructed in #44 , I am opening a new issue here. Not sure if this a proper issue, and as was discussed in the other thread, this most likely is not even fault of LB gradle plugin. Anyway, I will appreciate any help or advice on how I could proceed with this without resorting to Java 8 (which I haven't tried yet, but it should supposedly work).

So, I am trying to generate liquibase changelog based on changed JPA entities. My build.gradle looks like this:

buildscript {
    ext {
        springBootVersion = '2.1.0.RELEASE'
        runList = 'main'
        diffLog = '$projectDir/src/main/resources/db/changelog/db.changelog-master.xml'
    }
    repositories {
        mavenCentral()
//        maven {url "https://jitpack.io"}
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath 'org.liquibase:liquibase-gradle-plugin:2.0.1'
        classpath 'org.liquibase:liquibase-core'
//        classpath 'com.github.liquibase:liquibase:master-SNAPSHOT'
        classpath 'org.postgresql:postgresql:42.2.5'
        classpath 'org.liquibase.ext:liquibase-hibernate5:3.6'
        classpath 'org.springframework.data:spring-data-jpa:2.1.2.RELEASE'
    }
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.liquibase.gradle'

group = 'org.company'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 11.0
diffLog = '$projectDir/src/main/resources/db/changelog/db.changelog-{$version}.xml'

repositories {
    mavenCentral()
}

dependencies {
    implementation('org.springframework.boot:spring-boot-starter-data-jpa')
    implementation('org.springframework.boot:spring-boot-starter-security')
    implementation('org.springframework.boot:spring-boot-starter-webflux')
    implementation('org.springframework.session:spring-session-core')
    implementation('org.liquibase.ext:liquibase-hibernate5:3.6')
    implementation('org.liquibase:liquibase-core:3.6.2')
//  implementation('com.github.liquibase:liquibase:master-SNAPSHOT')
    implementation('io.reactivex.rxjava2:rxjava:2.2.3')
    implementation("org.hsqldb:hsqldb:2.4.1")
    implementation("org.postgresql:postgresql:42.2.5")
    compileOnly('org.projectlombok:lombok:1.18.4')

    testImplementation('org.springframework.boot:spring-boot-starter-test')
    testImplementation('io.projectreactor:reactor-test')
    testImplementation('org.springframework.security:spring-security-test')

    liquibaseRuntime('org.springframework.boot:spring-boot-starter-data-jpa:2.1.0.RELEASE')
    liquibaseRuntime('org.liquibase.ext:liquibase-hibernate5:3.6')
    liquibaseRuntime('org.liquibase:liquibase-core:3.6.2')
//    liquibaseRuntime('com.github.liquibase:liquibase:master-SNAPSHOT')
    liquibaseRuntime("org.postgresql:postgresql:42.2.5")
    liquibaseRuntime sourceSets.main.output
}

liquibase {
    activities {
        main {
            changeLogFile project.ext.diffLog
            url 'jdbc:postgresql://localhost:5432/database'
            username 'username'
            password 'password'
            referenceUrl 'hibernate:spring:org.company.warehouse.db?' +
                    'dialect=org.hibernate.dialect.PostgreSQL94Dialect&' +
                    'hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&' +
                    'hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy'
            referenceDriver 'liquibase.ext.hibernate.database.connection.HibernateDriver'
            logLevel 'debug'
        }
        runList = project.ext.runList
    }
}

A log from running gradle task in intellij:

Task :diffChangeLog liquibase-plugin: Running the 'main' activity... Starting Liquibase at Wed, 05 Dec 2018 19:45:12 CET (version 3.6.2 built at 2018-07-03 11:28:09) Unexpected error running Liquibase: URI is not hierarchical java.lang.IllegalArgumentException: URI is not hierarchical at java.base/java.io.File.(File.java:418) at liquibase.resource.FileSystemResourceAccessor.addRootPath(FileSystemResourceAccessor.java:51) at liquibase.resource.AbstractResourceAccessor.init(AbstractResourceAccessor.java:39) at liquibase.resource.FileSystemResourceAccessor.init(FileSystemResourceAccessor.java:44) at liquibase.resource.FileSystemResourceAccessor.(FileSystemResourceAccessor.java:26) at liquibase.integration.commandline.Main.doMigration(Main.java:949) at liquibase.integration.commandline.Main.run(Main.java:191) at liquibase.integration.commandline.Main.main(Main.java:129)

Now, a little bit of reading revealed that the fix for this is already merged in the PR https://github.com/liquibase/liquibase/pull/830, but the newest release on maven central is 3.6.2 from 4th July 2018, so the fix remains in master for now. So I tried to include a github repo dependency through jitpack - commented out lines in the build file - but I can't get it to work.

My question is, what options do I have to solve this for now? #44 mentions adding javax.xml.bind:jaxb-api as liquibaseRuntime dependency, so I did that:

liquibaseRuntime("javax.xml.bind:jaxb-api:2.3.1")

But the same thing happens. What steps could I take to properly troubleshoot this? I am not very knowledgeable about how Gradle and its plugins work.

stevesaliman commented 5 years ago

I'll keep an eye out for the next release to see if CORE-3343 gets resolved.

In the meantime, if the issue is truly fixed in the master branch, there are a couple of workarounds you could try...

Option 1:

  1. If you're the only one building your project, you can simply clone the master branch and run mvn -DskipTests install to install the latest Liquibase to your local maven "repository"

  2. Add mavenLocal() to your build.gradle in all the places that currently have mavenCentral(), making sure that mavenLocal comes before mavenCentral()

  3. Change the liquibaseRuntime Liquibase dependency to whatever version is in the Liquibase pom.xml.

Option 2: If more than one person is building your project, you'll need to do the same things as option 1, but with an extra step to upload your version of Liquibase to a shared repository. That repository would then need to be added to build.gradle, but instead of mavenLocal(), you'd have maven { url "http://myhost.mycompany.com/repo" }

jozefmorvay commented 5 years ago

I am building it alone, so option 1 it is. Your suggested solution appears to have work, the URI exception is now gone. It still doesn't work ,though:

Unexpected error running Liquibase: java.lang.NullPointerException
liquibase.exception.LiquibaseException: liquibase.command.CommandExecutionException: java.lang.NullPointerException
    at liquibase.integration.commandline.CommandLineUtils.doDiff(CommandLineUtils.java:200)
    at liquibase.integration.commandline.Main.doMigration(Main.java:1004)
    at liquibase.integration.commandline.Main.lambda$run$0(Main.java:187)
    at liquibase.Scope.child(Scope.java:125)
    at liquibase.Scope.child(Scope.java:106)
    at liquibase.Scope.child(Scope.java:138)
    at liquibase.Scope.child(Scope.java:142)
    at liquibase.integration.commandline.Main.run(Main.java:186)
    at liquibase.integration.commandline.Main.main(Main.java:125)
Caused by: liquibase.command.CommandExecutionException: java.lang.NullPointerException
    at liquibase.command.AbstractCommand.execute(AbstractCommand.java:24)
    at liquibase.integration.commandline.CommandLineUtils.doDiff(CommandLineUtils.java:198)
    ... 8 common frames omitted
Caused by: java.lang.NullPointerException: null
    at liquibase.snapshot.jvm.JdbcSnapshotGenerator.getDatabaseCatalogNames(JdbcSnapshotGenerator.java:147)
    at liquibase.snapshot.jvm.CatalogSnapshotGenerator.snapshotObject(CatalogSnapshotGenerator.java:34)
    at liquibase.snapshot.jvm.JdbcSnapshotGenerator.snapshot(JdbcSnapshotGenerator.java:66)
    at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:49)
    at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:286)
    at liquibase.snapshot.DatabaseSnapshot.init(DatabaseSnapshot.java:96)
    at liquibase.snapshot.DatabaseSnapshot.<init>(DatabaseSnapshot.java:59)
    at liquibase.snapshot.JdbcDatabaseSnapshot.<init>(JdbcDatabaseSnapshot.java:38)
    at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:215)
    at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:188)
    at liquibase.command.core.DiffCommand.createReferenceSnapshot(DiffCommand.java:221)
    at liquibase.command.core.DiffCommand.createDiffResult(DiffCommand.java:143)
    at liquibase.command.core.DiffCommand.run(DiffCommand.java:135)
    at liquibase.command.AbstractCommand.execute(AbstractCommand.java:19)
    ... 9 common frames omitted

This is caused by some weird class, which I do not understand the purpose of. It just returns null/0/false for everything. So then I tried removing

referenceDriver 'liquibase.ext.hibernate.database.connection.HibernateDriver'

and replaced the line with:

driver 'org.postgresql.Driver'

But that amounted to getting a new exception instead:

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:sk.imuna.warehouse.db?dialect=org.hibernate.dialect.PostgreSQL94Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy)
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:sk.imuna.warehouse.db?dialect=org.hibernate.dialect.PostgreSQL94Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy)
    at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:131)
    at liquibase.integration.commandline.Main.createReferenceDatabaseFromCommandParams(Main.java:1407)
    at liquibase.integration.commandline.Main.doMigration(Main.java:1005)
    at liquibase.integration.commandline.Main.lambda$run$0(Main.java:187)
    at liquibase.Scope.child(Scope.java:125)
    at liquibase.Scope.child(Scope.java:106)
    at liquibase.Scope.child(Scope.java:138)
    at liquibase.Scope.child(Scope.java:142)
    at liquibase.integration.commandline.Main.run(Main.java:186)
    at liquibase.integration.commandline.Main.main(Main.java:125)
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:sk.imuna.warehouse.db?dialect=org.hibernate.dialect.PostgreSQL94Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy)
    at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:247)
    at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:142)
    at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:96)
    ... 9 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:sk.imuna.warehouse.db?dialect=org.hibernate.dialect.PostgreSQL94Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy)
    at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:193)
    ... 11 common frames omitted

No idea what that means since postgre driver is clearly listed as a liquibaseRuntime dependency, and I have seen other liquibase configurations that looked just like mine and worked.

Anyway, this is just me ranting, your suggestion was helpful. The follow up problems are not related to this issue, or the plugin in general.

Kr0oked commented 5 years ago

The issue got resolved in Liquibase 3.6.3. You can find a working example in my repo. You just have to use the following:

liquibaseRuntime 'org.liquibase:liquibase-core:3.6.3'

jozefmorvay commented 5 years ago

@Kr0oked very cool. it works now.