0

I am using JHipster 4.5.4 with Gradle as build system and would like to add Gradle Tasks for executing Liquibase tasks such as validate or reset. I used the liquibaseDiffChangelog task that ships with JHipster as a template. This task is defined like this:

task liquibaseDiffChangelog(dependsOn: compileJava, type: JavaExec) {
    group = "liquibase"

    if (OperatingSystem.current().isWindows()) {
        dependsOn pathingLiquibaseJar
        doFirst {
            classpath = files(pathingLiquibaseJar.archivePath)
        }
    } else {
        classpath sourceSets.main.runtimeClasspath
        classpath configurations.liquibase
    }
    main = "liquibase.integration.commandline.Main"

    args "--changeLogFile=src/main/resources/config/liquibase/changelog/" + buildTimestamp() +"_changelog.xml"
    args "--referenceUrl=hibernate:spring:at.project.domain?dialect=org.hibernate.dialect.MySQL5InnoDBDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy"
    args "--username=testapp_db_user"
    args "--password=secret"
    args "--url=jdbc:mysql://localhost:3306/testapp_db"
    args "--driver=com.mysql.jdbc.Driver"
    args "diffChangeLog"
}

I started with simply exchangin the diffChangeLog with validate but then receive classpath errors. I also added a classpath argument and ended up with a task definition like this:

task liquibaseValidate(dependsOn: compileJava, type: JavaExec) {
    group = "liquibase"

    if (OperatingSystem.current().isWindows()) {
        dependsOn pathingLiquibaseJar
        doFirst {
            classpath = files(pathingLiquibaseJar.archivePath)
        }
    } else {
        classpath sourceSets.main.runtimeClasspath
        classpath configurations.liquibase
    }
    main = "liquibase.integration.commandline.Main"

    args "--changeLogFile=./build/resources/main/config/liquibase/master.xml"
    args "--referenceUrl=hibernate:spring:at.project.domain?dialect=org.hibernate.dialect.MySQL5InnoDBDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy"
    args "--username=testapp_db_user"
    args "--password=secret"
    args "--url=jdbc:mysql://localhost:3306/testapp_db"
    args "--driver=com.mysql.jdbc.Driver"
    args "--classpath=./build/resources/main/config/liquibase/changelog/"
    args "validate"
}

The master file gets read, as it mentions the correct file name, so this part is fine. But it does not recognize the path for the actual changeset files, which are referenced in the master.xml file. This is the error message:

19:51:04.292 [main] ERROR liquibase - classpath:config/liquibase/changelog/00000000000000_initial_schema.xml does not exist
liquibase.exception.ChangeLogParseException: liquibase.exception.SetupException: classpath:config/liquibase/changelog/00000000000000_initial_schema.xml does not exist
        at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:27)
        at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:229)
        at liquibase.Liquibase.validate(Liquibase.java:1443)
        at liquibase.integration.commandline.Main.doMigration(Main.java:1102)
        at liquibase.integration.commandline.Main.run(Main.java:188)
        at liquibase.integration.commandline.Main.main(Main.java:103)
Caused by: liquibase.exception.SetupException: classpath:config/liquibase/changelog/00000000000000_initial_schema.xml does not exist
        at liquibase.changelog.DatabaseChangeLog.handleChildNode(DatabaseChangeLog.java:322)
        at liquibase.changelog.DatabaseChangeLog.load(DatabaseChangeLog.java:282)
        at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:25)
        ... 5 common frames omitted
Caused by: liquibase.exception.ChangeLogParseException: classpath:config/liquibase/changelog/00000000000000_initial_schema.xml does not exist
        at liquibase.parser.core.xml.XMLChangeLogSAXParser.parseToNode(XMLChangeLogSAXParser.java:100)
        at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:17)
        at liquibase.changelog.DatabaseChangeLog.include(DatabaseChangeLog.java:478)
        at liquibase.changelog.DatabaseChangeLog.handleChildNode(DatabaseChangeLog.java:320)
        ... 7 common frames omitted

How can I add the classpath correctly?

Gaël Marziou
  • 16,028
  • 4
  • 38
  • 49
Stefan
  • 679
  • 2
  • 9
  • 21

1 Answers1

2

Related to this JHipster issue, you need to remove classpath: from your changelog paths in master.xml (located at src/main/resources/config/liquibase/master.xml). This will let you use other liquibase tasks than liquibaseDiffChangeLog. This should be fixed in the next release (v4.6.2+).

Jon Ruddell
  • 6,244
  • 1
  • 22
  • 40