Want to deploy your JVM, Node.js and Go apps effortlessly to AWS? Try our service Boxfuse

Gradle Plugin

The Flyway Open-Source Gradle plugin supports Gradle 3.x and Gradle 4.x running on Java 8 or Java 9. The Flyway Enterprise Gradle plugin also supports Java 7.


plugins {
    id "org.flywaydb.flyway" version "5.0.7"
buildscript {
    repositories {
        maven {
            url "s3://flyway-repo/release"
            credentials(AwsCredentials) {
                accessKey 'your-flyway-pro-user'
                secretKey 'your-flyway-pro-password'
    dependencies {
        classpath "org.flywaydb.pro:flyway-gradle-plugin:5.0.7"

apply plugin: 'org.flywaydb.flyway'
buildscript {
    repositories {
        maven {
            url "s3://flyway-repo/release"
            credentials(AwsCredentials) {
                accessKey 'your-flyway-enterprise-user'
                secretKey 'your-flyway-enterprise-password'
    dependencies {
        classpath "org.flywaydb.enterprise:flyway-gradle-plugin:5.0.7"

apply plugin: 'org.flywaydb.flyway'


Name Description
flywayMigrate Migrates the database
flywayClean Drops all objects in the configured schemas
flywayInfo Prints the details and status information about all the migrations
flywayValidate Validates the applied migrations against the ones available on the classpath
flywayUndo Flyway Pro Undoes the most recently applied versioned migration
flywayBaseline Baselines an existing database, excluding all migrations up to and including baselineVersion
flywayRepair Repairs the schema history table


The Flyway Gradle plugin can be configured in a wide variety of following ways, which can all be combined at will.

Build script (single database)

The easiest way is to simply define a Flyway section in your build.gradle:

flyway {
    url = 'jdbc:h2:mem:mydb'
    user = 'myUsr'
    password = 'mySecretPwd'
    schemas = ['schema1', 'schema2', 'schema3']
    placeholders = [
        'keyABC': 'valueXYZ',
        'otherplaceholder': 'value123'

Build script (multiple databases)

To migrate multiple database you have the option to extend the various Flyway tasks in your build.gradle:

task migrateDatabase1(type: org.flywaydb.gradle.task.FlywayMigrateTask) {
    url = 'jdbc:h2:mem:mydb1'
    user = 'myUsr1'
    password = 'mySecretPwd1'

task migrateDatabase2(type: org.flywaydb.gradle.task.FlywayMigrateTask) {
    url = 'jdbc:h2:mem:mydb2'
    user = 'myUsr2'
    password = 'mySecretPwd2'

Gradle properties

The plugin can also be configured using Gradle properties. Their can be passed either directly via the command-line:

> gradle -Pflyway.user=myUsr -Pflyway.schemas=schema1,schema2 -Pflyway.placeholders.keyABC=valXYZ

or via a gradle.properties file:


# List are defined as comma-separated values

# Individual placeholders are prefixed by flyway.placeholders.

They can they be accessed as follows from your build.gradle:


Environment Variables

To make it ease to work with cloud and containerized environments, Flyway also supports configuration via environment variables. Check out the Flyway environment variable reference for details.

System properties

Configuration can also be supplied directly via the command-line using JVM system properties:

> gradle -Dflyway.user=myUser -Dflyway.schemas=schema1,schema2 -Dflyway.placeholders.keyABC=valueXYZ

Config files

Config files are supported by the Flyway Gradle plugin. If you are not familiar with them, check out the Flyway config file structure and settings reference first.

Flyway will search for and automatically load the <user-home>/flyway.conf config file if present.

It is also possible to point Flyway at one or more additional config files. This is achieved by supplying the System property flyway.configFiles as follows:

> gradle -Dflyway.configFiles=path/to/myAlternativeConfig.conf flywayMigrate

To pass in multiple files, separate their names with commas:

> gradle -Dflyway.configFiles=path/to/myAlternativeConfig.conf,other.conf flywayMigrate

Relative paths are relative to the directory containing your build.gradle file.

Alternatively you can also use the FLYWAY_CONFIG_FILES environment variable for this. When set it will take preference over the command-line parameter.

> export FLYWAY_CONFIG_FILES=path/to/myAlternativeConfig.conf,other.conf

By default Flyway loads configuration files using UTF-8. To use an alternative encoding, pass the system property flyway.configFileEncoding as follows:

> gradle -Dflyway.configFileEncoding=ISO-8859-1 flywayMigrate

This is also possible via the flyway section of your build.gradle or via Gradle properties, as described above.

Alternatively you can also use the FLYWAY_CONFIG_FILE_ENCODING environment variable for this. When set it will take preference over the command-line parameter.


Overriding order

The Flyway Gradle plugin has been carefully designed to load and override configuration in a sensible order.

Settings are loaded in the following order (higher items in the list take precedence over lower ones):

  1. System properties
  2. Environment variables
  3. Custom config files
  4. Gradle properties
  5. Flyway configuration section in build.gradle
  6. <user-home>/flyway.conf
  7. Flyway Gradle plugin defaults

The means that if for example flyway.url is both present in a config file and passed as -Dflyway.url= from the command-line, the JVM system property passed in via the command-line will take precedence and be used.

Gradle: migrate