Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ant integration seems to be broken #2388

Closed
mirkobeine opened this issue Jan 20, 2022 · 4 comments · Fixed by #2429
Closed

ant integration seems to be broken #2388

mirkobeine opened this issue Jan 20, 2022 · 4 comments · Fixed by #2429
Assignees
Labels
BNoUpgradePath Cannot upgrade to next version DBMariaDB IntegrationAnt
Milestone

Comments

@mirkobeine
Copy link

Environment

Liquibase Version: 4.6.2, 4.7.0

Liquibase Integration & Version: ant 1.10.12

Liquibase Extension(s) & Version:

Database Vendor & Version: MariaDB 10.3

Operating System Type & Version: Windows 10, JDK 16

Description

We're in the process of upgrading an existing project. Part of the upgrade is to upgrade liquibase from version 3.5.3 to >= 4.6.2.
We use an ant build file to setup / tear down our local development database, which includes applying our liquibase migrations.
To do so, we use the ant integration tasks provided by liquibase, e.g. <liquibase:updateDatabase />.

Everything works fine with liquibase 3.5.3 when executing the build file tasks from our IDE or from a console.

However, when trying to execute the same ant tasks with liquibase 4.6.2 oder 4.7.0, the execution fails with a ClassNotFoundException for liquibase/repackaged/org/apache/tools/ant/Task.

We haven't tried other versions of liquibase. Changing everything back to liquibase 3.5.3 immediately resolves the problem.

Steps To Reproduce

  1. create build file that defines tasks utilizing liquibase 4.6.2 or 4.7.0
  2. define a simple task
  3. try to run the task
  4. error

Actual Behavior

Sample build file:

<?xml version="1.0" encoding="utf-8"?>
<project name="sample_project" default="info" xmlns:liquibase="antlib:liquibase.integration.ant">

    <taskdef resource="liquibase/integration/ant/antlib.xml" uri="antlib:liquibase.integration.ant">
        <classpath path="../liquibase/lib/liquibase-4.6.2.jar"/>
    </taskdef>

    <target name="info">
        <echo>TEST</echo>
    </target>

</project>

Stack trace:

E:\Development\idea\spring-boot\hyperion\backend\build.xml:4: The following error occurred while executing this line:
jar:file:/E:/Development/idea/spring-boot/hyperion/liquibase/lib/liquibase-4.6.2.jar!/liquibase/integration/ant/antlib.xml:9: taskdef A class needed by class liquibase.integration.ant.GenerateChangeLogTask cannot be found: liquibase/repackaged/org/apache/tools/ant/Task
 using the classloader AntClassLoader[E:\Development\idea\spring-boot\hyperion\liquibase\lib\liquibase-4.6.2.jar]
	at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:571)
	at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:421)
	at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:275)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
	at org.apache.tools.ant.Task.perform(Task.java:350)
	at org.apache.tools.ant.Target.execute(Target.java:449)
	at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:184)
	at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:93)
	at org.apache.tools.ant.Main.runBuild(Main.java:809)
	at org.apache.tools.ant.Main.startAnt(Main.java:223)
	at org.apache.tools.ant.Main.start(Main.java:190)
	at org.apache.tools.ant.Main.main(Main.java:274)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:31)
Caused by: jar:file:/E:/Development/idea/spring-boot/hyperion/liquibase/lib/liquibase-4.6.2.jar!/liquibase/integration/ant/antlib.xml:9: taskdef A class needed by class liquibase.integration.ant.GenerateChangeLogTask cannot be found: liquibase/repackaged/org/apache/tools/ant/Task
 using the classloader AntClassLoader[E:\Development\idea\spring-boot\hyperion\liquibase\lib\liquibase-4.6.2.jar]
	at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:603)
	at org.apache.tools.ant.taskdefs.Definer.loadProperties(Definer.java:401)
	at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:263)
	at org.apache.tools.ant.taskdefs.Antlib.execute(Antlib.java:181)
	at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:419)
	... 20 more
Caused by: java.lang.NoClassDefFoundError: liquibase/repackaged/org/apache/tools/ant/Task
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
	at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1128)
	at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1296)
	at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1350)
	at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1313)
	at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1068)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
	at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1128)
	at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1296)
	at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1350)
	at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1313)
	at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1068)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:466)
	at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:569)
	... 24 more
Caused by: java.lang.ClassNotFoundException: liquibase.repackaged.org.apache.tools.ant.Task
	at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1362)
	at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1313)
	at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1068)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
	... 43 more
E:\Development\idea\spring-boot\hyperion\backend\build.xml:4: The following error occurred while executing this line:
jar:file:/E:/Development/idea/spring-boot/hyperion/liquibase/lib/liquibase-4.6.2.jar!/liquibase/integration/ant/antlib.xml:9: taskdef A class needed by class liquibase.integration.ant.GenerateChangeLogTask cannot be found: liquibase/repackaged/org/apache/tools/ant/Task
 using the classloader AntClassLoader[E:\Development\idea\spring-boot\hyperion\liquibase\lib\liquibase-4.6.2.jar]
	at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:571)
	at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:421)
	at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:275)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
	at org.apache.tools.ant.Task.perform(Task.java:350)
	at org.apache.tools.ant.Target.execute(Target.java:449)
	at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:184)
	at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:93)
	at org.apache.tools.ant.Main.runBuild(Main.java:809)
	at org.apache.tools.ant.Main.startAnt(Main.java:223)
	at org.apache.tools.ant.Main.start(Main.java:190)
	at org.apache.tools.ant.Main.main(Main.java:274)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:31)
Caused by: jar:file:/E:/Development/idea/spring-boot/hyperion/liquibase/lib/liquibase-4.6.2.jar!/liquibase/integration/ant/antlib.xml:9: taskdef A class needed by class liquibase.integration.ant.GenerateChangeLogTask cannot be found: liquibase/repackaged/org/apache/tools/ant/Task
 using the classloader AntClassLoader[E:\Development\idea\spring-boot\hyperion\liquibase\lib\liquibase-4.6.2.jar]
	at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:603)
	at org.apache.tools.ant.taskdefs.Definer.loadProperties(Definer.java:401)
	at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:263)
	at org.apache.tools.ant.taskdefs.Antlib.execute(Antlib.java:181)
	at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:419)
	... 20 more
Caused by: java.lang.NoClassDefFoundError: liquibase/repackaged/org/apache/tools/ant/Task
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
	at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1128)
	at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1296)
	at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1350)
	at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1313)
	at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1068)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
	at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1128)
	at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1296)
	at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1350)
	at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1313)
	at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1068)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:466)
	at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:569)
	... 24 more
Caused by: java.lang.ClassNotFoundException: liquibase.repackaged.org.apache.tools.ant.Task
	at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1362)
	at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1313)
	at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1068)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
	... 43 more

Expected/Desired Behavior

The integration works.

Additional Context

@mirkobeine
Copy link
Author

Did some digging. I'm not a maven-shade expert, but apparently maven shade was introduced with this commit.

This seems to be the change that causes the issue by relocating "org.apache" to "liquibase.repackaged.org.apache" on a bytecode level:

<relocations>
  <relocation>
    <pattern>org.apache</pattern>
    <shadedPattern>liquibase.repackaged.org.apache</shadedPattern>
  </relocation>
  <relocation>
    <pattern>com.opencsv</pattern>
    <shadedPattern>liquibase.repackaged.com.opencsv</shadedPattern>
  </relocation>
</relocations>

I suspect that this will also rewrite the byte code for the ant integration located under "liquibase.integration.ant", thus leading to the attempt to load classes from "liquibase.repackaged.org.apache.tools.ant" instead of "org.apache.tools.ant".

A simple include or exclude in the relocation configuration should solve the issue.
I'd happily provide a PR, but I can't get the 4.6.2 test suite to run green(there are failing tests).

@kataggart
Copy link
Contributor

Thanks @mirkobeine for the digging! We will take a look.

@kataggart kataggart added daily_review BNoUpgradePath Cannot upgrade to next version labels Jan 25, 2022
@nvoxland
Copy link
Contributor

Thanks @mirkobeine, there is a few issues that are being impacted by that too. The shading is apparently not as smart as we were expecting...

I can take care of the PR and coordinate it with the other related issues.

@nvoxland nvoxland moved this from To Do to Code Review in Conditioning++ Jan 27, 2022
@suryaaki2 suryaaki2 moved this from Code Review to Ready for Handoff (In JIRA) in Conditioning++ Feb 2, 2022
@XDelphiGrl XDelphiGrl self-assigned this Feb 7, 2022
@XDelphiGrl
Copy link
Contributor

XDelphiGrl commented Feb 7, 2022

The Ant task ant databaseUpdate successfully deploys objects to a MariaDB database.

Successful ant databaseUpdate Output by Fix Build

Buildfile: C:\Users\erz\work\DaticalDB-testing\liquibase-ant\build.xml

prepare:

databaseUpdate:
[liquibase:updateDatabase] Starting Liquibase.
[liquibase:updateDatabase] Creating database history table with name: testdb1.DATABASECHANGELOG
[liquibase:updateDatabase] Running Changeset: com/example/mariadb_community_changelog.xml::111::createTable::Liquibase Pro User
[liquibase:updateDatabase] Table TABLEA1 created
[liquibase:updateDatabase] ChangeSet com/example/mariadb_community_changelog.xml::111::createTable::Liquibase Pro User ran successfully in 17ms
///SNIP///
[liquibase:updateDatabase] Successfully released change log lock

BUILD SUCCESSFUL
Total time: 2 seconds

Error Before Fix

BUILD FAILED
C:\Users\erz\work\DaticalDB-testing\liquibase-ant\build.xml:12: The following error occurred while executing this line:
jar:file:/C:/Users/erz/work/DaticalDB-testing/liquibase-ant/lib/liquibase.jar!/liquibase/integration/ant/antlib.xml:9: taskdef A class needed by class liquibase.integration.ant.GenerateChangeLogTask cannot be found: liquibase/repackaged/org/apache/tools/ant/Task
 using the classloader AntClassLoader[C:\Users\erz\work\DaticalDB-testing\liquibase-ant\changelog;C:\Users\erz\work\DaticalDB-testing\liquibase-ant\lib\liquibase.jar;C:\Users\erz\work\DaticalDB-testing\liquibase-ant\lib\mariadb-java-client-2.7.3.jar;C:\Users\erz\work\DaticalDB-testing\liquibase-ant\lib\mssql-jdbc-8.1.0.jre8-preview.jar;C:\Users\erz\work\DaticalDB-testing\liquibase-ant\lib\postgresql-42.2.18.jar]

NOTE If you do not have snakeyaml.jar in your Ant classpath, you will see errors loading the following services: liquibase.license.LicenseService, liquibase.parser.ChangeLogParser and liquibase.hub.HubService. You can ignore these errors if you do not need any those services; in particular the Liquibase Ant Integration does not support Liquibase Hub. The errors are mitigated by dropping the snakeyaml.jar into your liquibase/lib directory in the Ant project.


Test Environment
Liquibase Core: dont-shade-all-apache/1320/34ef85, Pro: master/476/282bb0
PR #2429
Ant 1.10.11
MariaDB 10.6

Conditioning++ automation moved this from Ready for Handoff (In JIRA) to Done Feb 7, 2022
@nvoxland nvoxland added this to the v4.8.0 milestone Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BNoUpgradePath Cannot upgrade to next version DBMariaDB IntegrationAnt
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

4 participants