Gradle dynamic product flavor parameters

I’m trying to configure the parameter resConfigs in android.defaultConfig {}. This can take multiple parameters such as resConfigs ‘en’, ‘fa’. Now I have separated this so i have resConfig specified for each product flavor separately.

android {
    productFlavors.whenObjectAdded { flavor ->
        def flavorData = rootProject.ext[flavor.name]
        flavor.resConfigs flavorData.resConfig.split(",")
    }

    productFlavors {
        customization{}
    }
}

In a separate file i have

ext {

   apply from: 'locales.gradle'

   customization = [
       resConfig = rootProject.ext.locales.main
   ]
}

Now i want to have locales defined in a separate file as well (locales.gradle):

ext {
    locales = [
        main : "en,fr"
    ]
}

This works perfectly…however i would like to generate the locales.gradle file dynamically before the app is build, so the resConfig parameters get picked up on time. I want to run the task that generates this file from another module, the task is executed, but unfortunately not the before the product flavor gets assigned its parameters.

I have tried:

prebuild.dependsOn ':mymodule:run'

`commandLine 'cmd', '.\\gradlew', ':mymodule:run'

    tasks.whenTaskAdded { task ->
        if (task.name.contains('assembleDebugFull')) {
            task.dependsOn ':mymodule:run'
        }
    }

Nothing executes the modules task before the product flavor is generated.

How can i run a task normally in gradle without that much of a hussle.