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>

DatafixFilter.java:


package pl.pzu.tajpan.dziennik.liquibase;

import liquibase.changelog.IncludeAllFilter;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DatafixFilter implements IncludeAllFilter {
    public static final String SD_SQL_FILES = "SOME_REGEX$)";
    private final Pattern pattern = Pattern.compile(SD_SQL_FILES);
    @Override
    public boolean include(String s) {
        Matcher matcher = pattern.matcher(s);
        return matcher.find();
    }
}

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.

What if you added this to your liquibase-maven-plugin definition:

                <dependencies>
                    <dependency>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${project.artifactId}</artifactId>
                    </dependency>
                </dependencies>

?

That should make it so that the current artifact gets added as a dependency to running liquibase-maven-plugin which should make it available.

Nathan

Hi, thank you for proposing a solution. Unfortunately now I get a compilation error:

Some problems were encountered while processing the POMs:
[FATAL] 'dependencies.dependency.[MODULE_NAME:0.01-SNAPSHOT]' for MODULE_NAME:0.01-SNAPSHOT is referencing itself. @ line 45, column 21