Run Gradle task with command line parameters several times from Groovy script
Asked Answered
G

0

0

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?

Guadiana answered 4/2, 2022 at 22:47 Comment(2)
What problem are you trying to solve by running a task multiple times with different parameters? What version of Gradle are you using? Does setting buildName help?Taco
The problem looks to be in dependsOn name which may depends on itself. Maybe you should debug this and share more info ? Or I suggest you to create your tasks and then create a runAll task with GradleBuild API that call an array of your tasks... not a dependency...Mcdowell

© 2022 - 2024 — McMap. All rights reserved.