0

I am using liquibase-maven-plugin in my spring boot application. As propertyFile attribute, I am using an YAML file:

The liquibase-maven-plugin configuration in my POM file:

<plugin>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-maven-plugin</artifactId>
    <version>4.7.1</version>
    <configuration>
        <verbose>true</verbose>
        <propertyFile>${project.basedir}/../other-project/src/main/resources/config/app-configuration.yml
        </propertyFile>
        <outputDirectory>${project.basedir}/src/main/resources/changelog/</outputDirectory>
        <outputChangeLogFile>${project.basedir}/src/main/resources/changelog/changelog-master.xml
        </outputChangeLogFile>
        <diffChangeLogFile>${project.basedir}/src/main/resources/changelog/diff-changelog-master.xml
        </diffChangeLogFile>
    </configuration>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.liquibase.ext/liquibase-hibernate5 -->
        <dependency>
            <groupId>org.liquibase.ext</groupId>
            <artifactId>liquibase-hibernate5</artifactId>
            <version>4.7.1</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.24</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
</plugin>

The YAML property file:

spring:
  datasource:
    db_name: ${DB_NAME_DEFINED_IN_ENVIRONMENT:my_db}
    db_url: jdbc:postgresql://${POSTGRES_HOSTNAME_DEFINED_IN_ENVIRONMENT:localhost}:${POSTGRES_PORT_DEFINED_IN_ENVIRONMENT:5432}
    url: ${spring.datasource.db_url}/${spring.datasource.db_name}
    driverClassName: org.postgresql.Driver
    driver: org.postgresql.Driver 
    username: ${POSTGRES_USER_DEFINED_IN_ENVIRONMENT:user}
    password: ${POSTGRES_PASSWORD_DEFINED_IN_ENVIRONMENT:password}

When I run the goal generateChangeLog I got this:

[INFO] 
[INFO] --- liquibase-maven-plugin:4.7.1:generateChangeLog (default-cli) @ user-management ---
[INFO] ------------------------------------------------------------------------
[INFO] Loading artifacts into URLClassLoader
...
[project, pluginDescriptor]
[INFO] Parsing Liquibase Properties File
[INFO]   File: C:\projects\../other-project/src/main/resources/config/user-management.yml
...
tarting Liquibase at 16:26:51 (version 4.7.1 #1239 built at 2022-01-20 20:31+0000)
[INFO] Settings
----------------------------
[INFO]     driver: org.postgresql.Driver
[INFO]     url: ${spring.datasource.db_url}/${spring.datasource.db_name}
[INFO]     username: *****
[INFO]     password: *****
[INFO]     use empty password: false
[INFO]     properties file: C:\projects\../other-project//src/main/resources/config/user-management.yml
[INFO]     properties file will override? false
[INFO]     clear checksums? false
[INFO]     defaultSchemaName: null
[INFO]     diffTypes: null
[INFO]     dataDir: null
[INFO] ------------------------------------------------------------------------
[INFO] Cannot load service: liquibase.database.Database: liquibase.ext.hibernate.database.HibernateSpringBeanDatabase Unable to get public no-arg constructor
[INFO] Cannot load service: liquibase.database.Database: liquibase.ext.hibernate.database.HibernateSpringPackageDatabase Unable to get public no-arg constructor
...
Connection could not be created to ${spring.datasource.db_url}/${spring.datasource.db_name} with driver org.postgresql.Driver.  Possibly the wrong driver for the given database URL

Apparently, it is reading the YAML file. But is is not parsing the expressions inside the ${...}. You can see that it is reading correctly the drive property, but not the urlone. I suspect that I should have to add some library on dependencies to allow to parse the expressions. Am I right? Which library?

Thanks,

Rafael Afonso

Rafael Afonso
  • 595
  • 1
  • 10
  • 28

1 Answers1

0

Accepted answer from this question: Liquibase Hibernate Plugin Does Not Work

The process they went through was:

  1. Download the source for the correct plugin project found here (https://github.com/liquibase/liquibase-hibernate/releases) in their case it was liquibase-hibernate4-3.5.
  2. Run mvn dependency:copy-dependencies. This dumps them into /target/dependency/. Copy all these jars and put them into your LIQUIBASE_HOME/lib directory.
  3. They are using Gradle so they used a custom task to copy all the dependencies. If you're using maven you can use the same step from 2 on your own project to fetch all your dependencies. They copied these libs from their output directory into the LIQUIBASE_HOME/lib directory.
task copyToLib(type: Copy) {
    into "$buildDir/output/libs"
    from configurations.runtime
}
  1. They also put the correct hibernate-liquibase-4.3.5.jar into the LIQUIBASE_HOME/lib directory.

That gave them all the dependencies needed for the plugin.

tabbyfoo
  • 355
  • 1
  • 8