Liquibase maven plugin - includeAll filter vs classpath

Hi all,
I’m a newbie here. I’ve searched the forum, but couldn’t find the answer.
I use Liquibase 4.6.2 as a Maven Plugin and wish to run it with “mvn clean install” or even “liquibase:update” a as part of my Bamboo pipeline to deploy DB datafixes.

My pom.xml:

 ...
> <dependencies>
>         <dependency>
>             <groupId>com.oracle.database.jdbc</groupId>
>             <artifactId>ojdbc8</artifactId>
>             <version>21.1.0.0</version>
>         </dependency>
>         <dependency>
>             <groupId>org.liquibase</groupId>
>             <artifactId>liquibase-core</artifactId>
>             <version>4.6.2</version>
>         </dependency>
>         <dependency>
>             <groupId>org.junit.jupiter</groupId>
>             <artifactId>junit-jupiter</artifactId>
>             <scope>test</scope>
>         </dependency>
> 
>     </dependencies>
>     <build>
>             <resources>
>                 <resource>
>                     <directory>src/main/resources</directory>
>                     <filtering>true</filtering>
>                 </resource>
>             </resources>
>         <plugins>
>             <plugin>
>                 <groupId>org.liquibase</groupId>
>                 <artifactId>liquibase-maven-plugin</artifactId>
>                 <version>4.6.2</version>               
>                 <executions>
>                     <execution>
>                         <goals>
>                             <goal>update</goal>
>                         </goals>
>                         <phase>pre-integration-test</phase>
>                     </execution>
>                 </executions>
>             </plugin>
>         </plugins>
>     </build>

My changelog file:


<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:pro="http://www.liquibase.org/xml/ns/pro"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd
      http://www.liquibase.org/xml/ns/pro
      http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.xsd">
    <includeAll path="datafix/dev/" relativeToChangelogFile="true"  **filter="pl.pzu.tajpan.dziennik.liquibase.DatafixFilter"** />
</databaseChangeLog>

My project structure:


Please notice the target directory with class DatafixFilter being present.

Run command (from project main directory):
mvn install -X -e -Dliquibase.driver=oracle.jdbc.driver.OracleDriver -Dliquibase.changeLogFile=db.changelog-datafixes-dev.xml -Dliquibase.url=jdbc:oracle:thin:@URL:PORT/SERVICE_NAME -Dliquibase.username=USERNAME -Dliquibase.password=PASSWORD -Dliquibase.logLevel=debug

The command fails due to classloader being unable to find changelog filter class:

Failed to execute goal org.liquibase:liquibase-maven-plugin:4.6.2:updateSQL (default) on project tajpan-dziennik-db: 
Error setting up or running Liquibase:
liquibase.exception.SetupException: pl.pzu.tajpan.dziennik.liquibase.DatafixFilter
Caused by: java.lang.ClassNotFoundException: pl.pzu.tajpan.dziennik.liquibase.DatafixFilter
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass (SelfFirstStrategy.java:50)

I’ve tried using various ways to add my class or jar file with my class to classpath ((-classpath / -Dclasspath -Dliquibase.classpath, copying jar to different locations) but to no avail.

What am I doing wrong? The error goes away after removing “filter” attribute from includeAll.

When you have a maven plugin like the liquibase-maven-plugin, it runs that in a different classloader than what contains your built application code.

If you add your project as a dependency of liquibase-maven-plugin then it will have access to it. Like:

                <plugin>
                    <groupId>org.liquibase</groupId>
                    <artifactId>liquibase-maven-plugin</artifactId>
                    <version>4.6.2</version>
                    <dependencies>
                        <dependency>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <goals>
                                <goal>update</goal>
                            </goals>
                            <phase>pre-integration-test</phase>
                        </execution>
                    </executions>
                </plugin>

Nathan