Hi all!
I have two GradleBuild tasks that run a series of other tasks to set up the database for the main and the othter tenants in a multitenancy environment:
task runDatabaseChangesForTenants(type: GradleBuild) {
dir = projectProperties.sfwDir
buildFile = "${projectProperties.sfwDir}/build.gradle"
tasks = [‘verificaGrants’, ‘printDatabaseInfo’, ‘atualizaDb’, ‘aplicarScriptsMd’, ‘aplicarMetadadosSfw’, ‘printDatabaseInvalidObjects’, ‘gravaDadosBannerAplicacaoSfw’]
startParameter.projectProperties = project.projectProperties
startParameter.projectProperties.runScript = project.projectProperties.runScriptsAutomaticallyQuestion
startParameter.projectProperties.rerunTasks = true
}
// Cópia do anterior mas sem a task ‘aplicarScriptsMd’ e com a alteração da task 'aplicarMetadadosSfwMainTenant’
task runDatabaseChangesMainTenant(type: GradleBuild) {
dir = projectProperties.sfwDir
buildFile = "${projectProperties.sfwDir}/build.gradle"
tasks = [‘verificaGrants’, ‘printDatabaseInfo’, ‘atualizaDb’, ‘aplicarMetadadosSfwMainTenant’, ‘printDatabaseInvalidObjects’, ‘gravaDadosBannerAplicacaoSfw’, ‘verificarClientemBanco’]
startParameter.projectProperties = project.projectProperties
startParameter.projectProperties.runScript = project.projectProperties.runScriptsAutomaticallyQuestion
}
I have a config file with the main and the other tenats configuration that I need to read to pass the data to the tasks above:
def runDatabaseChangesInstall(ehAmbienteCloud = false, configFile = ‘tenantConfig.groovy’) {
// se a propriedade ambienteCloud for true, a instalação deverá ser multi-tenancy,
// neste caso é necessário a existencia do arquivo tenantConfig.groovy.
if (ehAmbienteCloud) {
menssageInstaller("INSTALACAO MULTI-TENANCY ATIVADA", true)
File tenantConfigFile = file(configFile)
if (!tenantConfigFile.exists()) {
createTenantConfigFile()
}
ConfigSlurper tenantConfigSluper = new ConfigSlurper("tenancies")
ConfigObject configOj = tenantConfigSluper.parse(tenantConfigFile.toURI().toURL())
// se não contrar nenhum tenant configurado...
if (configOj.keySet().isEmpty()) {
throw new GradleException("ERRO: Nenhum Tenant configurado no arquivo tenantConfig.groovy, nao eh possivel continuar.")
}
// caso contrário, inicio a atualização dos tenants
printMessage "Os seguintes tenants serão atualizados:"
configOj.keySet().each { printMessage " - $it" }
def buildToExecuteMain = runDatabaseChangesMainTenant
def buildToExecute2nd = runDatabaseChangesForTenants
// para cada tenant do arquivo tenantConfig.groovy, executo o a task runDatabaseChanges
configOj.each { tenantConfig ->
menssageInstaller("ATUALIZANDO TENANT: $tenantConfig.key")
// Build do main tenant é diferente pois não aplica scripts do MD e a task de aplicar metadados é outra
if (tenantConfig.key == 'mainTenant') {
buildToExecuteMain.startParameter.projectProperties.databaseDir = 'install/db/main'
buildToExecuteMain.execute()
// Limpa a configuração pois senão as próximas execuções utilizarão o mesmo diretório erroneamente
buildToExecuteMain.startParameter.projectProperties?.remove('databaseDir')
} else {
buildToExecute2nd.startParameter.projectProperties.tenantConfig = tenantConfig
buildToExecute2nd.execute()
// Limpa a configuração pois senão as próximas execuções utilizarão o mesmo diretório erroneamente
buildToExecute2nd.startParameter.projectProperties?.remove('databaseDir')
}
}
}
// a instalação não é multi-tenancy, então executo a task antiga
else {
tasks.runDatabaseChanges.execute()
}
}
Problem is the second time this loop runs the runDatabaseChangesForTenants tasks it does not run at all, it’s like since it has run a first time it will not run again. ever.
Is there a way to run a task multiple times inside a loop? I’m on gradle 4.0, Gradle 4.2 and Java 8. Thanks in advance!!