'Run Gradle task with command line parameters several times from Groovy script

I am working on an Android project which uses a Gradle task with command line parameters. The task should be called from command line like that:
gradlew myTask -Parg1=aaa

Instead of calling it from command line I want to call this task from a Gradle file where I have all the arguments in a list. I need to create another task which runs myTask in a loop with all the arguments. By following this example I created the following code:

def data=['1', '2', '3']
project.task('runAll') {
    data.collect { count ->
        project.task('run_' + count, type: GradleBuild) {
            startParameter.projectProperties = ['arg1': count]
            tasks = ['myTask']
        }.name
    }.forEach { name ->
        dependsOn name
    }
}

When running individual tasks run_1, run_2, and run_3 everything works fine. If I run runAll, run_1 finishes successfully, but run_2 and run_3 crashes with the following error:

Included build C:\Projects\MyAwesomeApp\app has build path :app which is the same as included build C:\Projects\MyAwesomeApp\app

Can you help me solve this error?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source