1

I want to write the flyway connection detail to a file, so I can use these values in a custom JavaExec task. If you want to know more about it you can read: How to run a JavaExec gradle task with arguments when the task is called in finalizedBy?

I created a task that writes the url, user and password to a file and it works, but the problem is that it is always using the default values from the flyway {} block in the build.gradle file and ignores the overridden values in case flywayMigrate is run with props like this:

./gradlew flywayMigrate -Pflyway.user=admin -Pflyway.password=secret

Below you can see the task that writes the values to the file.

task writeArgstoFile {
    doFirst {
        mkdir "$rootProject.buildDir/check-db-standards"
        new File("${rootProject.buildDir}/check-db-standards/args").text = "${flyway.url}\n" +
                "${flyway.user}\n" +
                "${flyway.password}\n"
    }
}

flywayMigrate.finalizedBy(writeArgstoFile)
writeArgstoFile.finalizedBy(rootProject.checkOracleStandards)

How can I get the correct updated flyway values?

Dinu Nicolae
  • 1,019
  • 2
  • 17
  • 42
  • 1
    wont the `-P` set a temporary system variable? You will want to read [this](https://newbedev.com/how-to-pass-parameters-or-arguments-into-a-gradle-task) – Shark Dec 15 '21 at 10:05
  • 1
    Do note that, since you have a `flyway { ... }` block in your gradle script, `${flyway.user}` and `println flyway.user` will evaluate differently in that `doFirst`. First one calling into the flyway block you defined, second one reading the parameter the task got. – Shark Dec 15 '21 at 10:08

0 Answers0