liquibase / liquibase-gradle-plugin

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

Task prefix parameter (liquibaseTaskPrefix) cannot be set from within build.gradle #55

Closed kamenov closed 5 years ago

kamenov commented 5 years ago

If I try to set the property liquibaseTaskPrefix from inside build.gradle regardless of scope i.e.

liquibase {
    // Prefix commands to avoid naming conflicts - update will become dbUpdate
    liquibaseTaskPrefix = 'myPrefix'
    activities {
    ...
    }
}

i get an error

Could not set unknown property 'liquibaseTaskPrefix' for object of type org.liquibase.gradle.LiquibaseExtension.

If I pass the property as

gradle diff -PliquibaseTaskPrefix=abc

then it works

Ideally I would like to have it inside my liquibase closure, so that i don't configure it at every call with -P I can propose a pull request.

stevesaliman commented 5 years ago

The short answer for this request is to put liquibaseTaskPrefix=abc in your project's gradle.properties file. Doing this will meet your goal of not having to put it on the command line.

There is no good way use the liquibase configuration to change how the Liquibase tasks get created. Unless you're really interested in the technical details, you can probably stop reading here :smiley:

The long answer as to why there is no good way to do this has to do with order that Gradle does things, which looks like this:

  1. Gradle applies the plugin when it sees apply plugin or a plugins block in build.gradle
  2. The liquibase plugin creates the liquibase configuration and adds all the tasks when the plugin is applied.
  3. Gradle processes the liquibase configuration when it reaches it in the build.gradle file.
  4. Gradle runs requested tasks, with the right configuration.

This ordering causes some limitations for us with regard to defining task prefixes in the configuration.

The bottom line is that tasks get created before configurations are processed. A configuration is designed to affect how a plugin runs, not how the plugin is applied. This limitation is what led me to use Gradle properties to define the prefix task prefix. Properties will always exist before the plugin gets applied, and putting them in gradle.properties is just as good as having them in a configuration if you're looking for a permanent prefix for all users.

Bwvolleyball commented 5 months ago

That's not exactly the best answer for someone looking to wrap this plugin with their own specific needs, this is unfortunate, because I wanted to handle the setting of this property in my plugin, not with a specific, random property I need to add to every project that uses my plugin.