liquibase / liquibase-gradle-plugin

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

Question: Passing different argument for each task #106

Closed jasperjanuar closed 1 year ago

jasperjanuar commented 2 years ago

What I'm trying to achieve is I want to have the configuration in liquibase.properties to act as fallback values, and be able to override specific values for some of the gradle liquibase tasks:

Eg. diffChangelog should not append the changesets to my master changelog file but instead output them to a new file, therefore i want to overwrite the changelogFile value to something different.

Is this possible

stevesaliman commented 1 year ago

liquibase.properties already acts this way. It has the fallback values for properties that are explicitly specified. But

The current way to specify more specific values is by adding an activity to the liquibase block. These values can be static (like the changelogFile usually is), or it can be a property like project.ext.jdbcPassword for a password. With this mechanism, you can do powerful things like override the changelogFile with something like this:

def changeLogToUse = 'src/main/db/changelog.groovy'
if ( project.hasProperty("changelog") ) {
    changeLogToUse = project.ext.changelog
}

liquibase {
    activities {
        main {
            changelogFile changeLogToUse
        }
    }
}

Another way is to have a different activity for running diffChangeLog. This is what jHipster does. It generates a liquibase block like this:

project.ext.diffChangelogFile = "src/main/resources/config/liquibase/changelog/" + new Date().format("yyyyMMddHHmmss") + "_changelog.xml"
liquibase {
    activities {
        main {
            // regular args
        }
        diffLog {
            changelogFile project.ext.diffChangelogFile
            // other args
        }
    }
}

Then you can run gradlew -PrunList=diffLog diffChangelog and you'd get a new file each time you run it.

Finally, release 2.2.0 of the plugin, which will hopefully be released in the next day or two, has a new liquibaseExtraArgs property that you can use to specify properties to pass to Liquibase. These can override or add to the arguments in the liquibase block. In your example, you could run gradlew diffChangelog -PliquibaseExtraArgs="changelogFile=myChangeLog.groovy"

jasperjanuar commented 1 year ago

@stevesaliman this is exactly what I've been looking for! Thanks!

stevesaliman commented 1 year ago

Version 2.2.0 of the plugin has now been released, so you can use the liquibaseExtraArgs property now. Happy gradling!