Liquibase update task not using compiled classpath

Hi,
I have problem with liquibase plugin and dependecies.
During update task, liquibase don’t see compiled classes and throws ClassNotFoundException.
How to force setting classpath to compiled files in that update task ?

My structure is like (package and class names changed):
aproject\src\main\java\a\b\C.java

and class C implements CustomTaskChange.

Build.gradle looks like:

apply plugin:'java'
apply plugin: 'org.liquibase.gradle'
apply plugin: 'maven'
apply plugin: 'eclipse' 


buildscript {
    
    repositories {
           flatDir {
               dirs '............''
           }
           maven {
          url "http://.................."
            credentials {
                username = mavenUser
                password = mavenPassword
            }
        }        
    }
    dependencies {
        classpath ':ojdbc7'
        classpath ':otherLibraries'
        classpath 'org.liquibase:liquibase-core:3.4.2'
        classpath "org.liquibase:liquibase-gradle-plugin:1.2.1"
    }
}


repositories {   
    flatDir {
        dirs '..............'
    }     
    maven {
      url "http://........."
        credentials {
            username = mavenUser
            password = mavenPassword
        }
    }   
}

dependencies{
    compile ':otherLibrary'
    compile 'org.liquibase:liquibase-core:3.4.2'

}

liquibase {
 activities {
     
    XXXXX{
........
    }
  }
  runList = project.ext.runList
}

In my changelog.xml I have:

<changeSet id="0" author="XXX" runAlways="true" >
    <customChange class="a.b.C"/>
    <comment>Test C</comment>
 </changeSet>

Commands:

gradle clean build -PrunList=XXXXX

creates build catalog with compiled classess and jar
but when I type

gradle update -PrunList=XXXXX
I’ve got

Caused by: liquibase.parser.core.ParsedNodeException: liquibase.exception.CustomChangeException: java.lang.ClassNotFoundException: a.b.C
        at liquibase.change.custom.CustomChangeWrapper.load(CustomChangeWrapper.java:295)
        at liquibase.changelog.ChangeSet.toChange(ChangeSet.java:414)
        at liquibase.changelog.ChangeSet.handleChildNode(ChangeSet.java:359)
        at liquibase.changelog.ChangeSet.load(ChangeSet.java:290)
        at liquibase.changelog.DatabaseChangeLog.createChangeSet(DatabaseChangeLog.java:431)
        at liquibase.changelog.DatabaseChangeLog.handleChildNode(DatabaseChangeLog.java:259)
        at liquibase.changelog.DatabaseChangeLog.load(DatabaseChangeLog.java:230)
        at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:25)
        ... 122 more
Caused by: liquibase.exception.CustomChangeException: java.lang.ClassNotFoundException: a.b.C
        at liquibase.change.custom.CustomChangeWrapper.setClass(CustomChangeWrapper.java:96)
        at liquibase.change.custom.CustomChangeWrapper.load(CustomChangeWrapper.java:293)
        ... 129 more
Caused by: java.lang.ClassNotFoundException: a.b.C
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at liquibase.resource.CompositeResourceAccessor$CompositeClassLoader.loadClass(CompositeResourceAccessor.java:91)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at liquibase.change.custom.CustomChangeWrapper.setClass(CustomChangeWrapper.java:87)
        ... 130 more

Could anyone help me to resolve issue, please ?

Disclaimer: I’m not a Liquibase user

I feel there’s a “chicken and egg” problem going on here

  1. The Liquibase plugin uses the buildscript classpath
  2. The buildscript classpath is resolved before the JavaCompile task is executed
  3. You want Liquibase to load a class complied by the JavaCompile task

As a workaround you might need to move a.b.C to another project and specify

buildscript {
   dependencies {
      classpath project(':anotherProject') 
      ... 
   } 
} 

Ideally, the Liquibase plugin should define it’s own liquibase configuration which you could add dependencies to. It could then use it’s own classloader based on the configuration rather than using the buildscript classpath (removing the chicken or egg issue)

You should get in touch with the liquibase plugin developers. The plugin is currently very bare bones and cannot support your use case. It would need an option to specify the liquibase classpath (it currently just uses the buildscript classpath as @Lance_Java correctly pointed out).