Hello,
I have been struggling with finding a good way of calling a task twice with different configuration. I eventual come up with a “workaround” but feel it’s rater complicated consider I “just” want to call a task twice with different configuration.
Background info:
I’m using flyway gradle plugin to roll out database DDL and first step is to create the database schema with a system user, and second step is to roll out the rest of the DDL with the local user. So basic I want the task dbBootstrap to call dbCreateSchema and flywayMigrate with the sys configuration and then call flywayMigration with the default settings.
flyway {
locations = flywayLocations
url = flywayUrl.toString()
user = flywayDbuser.toString()
password = flywayDbpassword.toString()
…
}
task sysdbInit(group: ‘database’){
doFirst {
project.ext[‘flyway.user’] = ‘systemuser as sysdba’
project.ext[‘flyway.password’] = ‘****’
project.ext[‘flyway.locations’] = flywayCreateSchemaLocation
}
}
task dbCreateSchema(group: ‘database’, dependsOn: [‘sysdbInit’,‘flywayMigrate’]) {
flywayMigrate.mustRunAfter sysdbInit
mustRunAfter clean
}
task dbBootstrap(group: ‘database’, dependsOn: [‘dbCreateSchema’,‘flywayMigrate’]) {
mustRunAfter clean
}
As I understand gradle doesn’t allow to add the same task twice or more to the call tree, so as a workaround I created two gradle files. One have the dbCreateSchema and the sysdbInit task and the other has the dbBootstrap and default configuration
My script look like this:
task dbCreateSchema(type: GradleBuild, group: ‘database’) {
buildFile = “flywaydb-schema.gradle”
tasks = [‘dbCreateSchema’]
}
task dbBootstrap(group: ‘database’, dependsOn: [‘dbCreateSchema’,‘flywayMigrate’]) {
mustRunAfter clean
}
Is this the best way to solve this?
Thanks!
/Flemming