Quantcast
Channel: Gradle Forums - Latest posts
Viewing all articles
Browse latest Browse all 19854

Call task of another build.gradle file using a groovy method

$
0
0

Rather than “triggering” the task, you should change up the configuration a bit. It’s pretty common that people don’t use doLast {} when they should, but you actually have the opposite issue here. All of your code is actually configuration code that should run at configuration time, not at task execution time.

task buildOtherSmallProjects {
    dependsOn createTriggerTask('AAA', '../small-project-AAA/build.gradle', ['jar'])
    dependsOn createTriggerTask('CCC', '../small-project-CCC/build.gradle', ['jar'])
}

def createTriggerTask(projectName, relativeBuildFilePath, tasksToTrigger) {
    tasks.register("trigger${projectName}", GradleBuild) {
        buildFile = relativeBuildFilePath
        tasks = tasksToTrigger
    }
}

I also used register rather than create (task configuration avoidance). This avoids configuring the trigger tasks when you’re not needing to run them, but is not strictly necessary. You can stick to create if you want.


Viewing all articles
Browse latest Browse all 19854

Trending Articles