liquibase / liquibase-gradle-plugin

A Gradle plugin for Liquibase
Other
200 stars 59 forks source link

Running Java/Groovy classes as part of a changeset #17

Closed andygoossens closed 3 years ago

andygoossens commented 7 years ago

I am wondering whether it is possible to run a Java/Groovy/... class from the same Gradle module. When I tried it, it was giving me a java.lang.ClassNotFoundException.

Example with a XML changeset:

  <changeSet id="something" author="me">
    <customChange class="foo.HelloWorld"/>
  </changeSet>

I assume that the class isn't part of the classpath that the plugin uses. Putting the class in an external artifact and then adding a 'classpath' dependency on it becomes more complex than it should be. :-(

DKroot commented 7 years ago

I have a Gradle build that runs a custom Java/Groovy class from a custom dependency. So, if your class could run in a build task rather than in a changeset this should work.

stevesaliman commented 7 years ago

Another thing that comes to mind is that you might be able to put HelloWorld.groovy inside your project's buildSrc/src/main/groovy/foo directory. Classes in buildSrc shoudl automatically be part of the classpsth.

dgeissl commented 7 years ago

As far as i see it you can use the older buildscript plugin syntax and include jars with custom tasks etc. in the buildscript classpath. Not sure if it's needed for the jdbc drivers though:

buildscript {
    repositories {
        flatDir {
           dirs 'libs'
        }
        mavenCentral()
    }

    dependencies {
        classpath (
            // liquibase
            [group: 'org.liquibase', name:'liquibase-core', version:'3.5.3'],
            // gradle plugin
            [group: 'org.liquibase', name:'liquibase-gradle-plugin', version:'1.2.4'],
            // jdbc driver
            [group: 'com.ibm.db2', name: 'db2jcc', version: '3.59.81'],
            // our own extensions
            [name: 'liquibase-extensions', version: '1.0-SNAPSHOT']
        )
    }
}
dgeissl commented 7 years ago

Ok i tested a bit, and the classpath of a activity works for jdbc drivers but not for extensions as the extensions will not find the liquibase classes. So it seems extensions need to be attached to the buildscript classpath while jdbc drivers and ears/wars can be given to the activity classpath.

Not sure what can be done about it.

Edit: maybe it's that i used a method that was not present in liquibase 5.3.1 as i developed my changes against the latest version 3.5.3, ill check this out the next days

stevesaliman commented 5 years ago

Version 2.0.0 of the plugin adds liquibaseRuntime dependencies for setting up the classpath that Liquibase will use when it runs. Does this help solve the issue? If the custom code is part of the project itself, you can add liquibaseRuntime sourceSets.main.output as a dependency.

stevesaliman commented 3 years ago

Closed due to inactivity. If this is still an issue with the latest versions of Liquibase and the plugin, we can always open a new issue.