Configuring a Subproject just before afterEvaluate()

Background: I have many Gradle projects in several git repositories and many are downstream dependencies of each other. On our Jenkins CI server when an official change is Merged, it knows how to build each project individually (in the correct order) and correctly publishes to Artifactory before building the next downstream dependency (so the new changes are available for the downstream Gradle project).

Problem: This all works great Except if I want verify a patch being worked in Jenkins. I dont want to officially build the patch and upload its artifacts into Artifactory, so I’m unable to build it downstream dependencies. I’m working on a solution that uses the Artifacts that were Archived by Jenkins (in Jenkins) and trying to figure out a way override the external dependency in Gradle with a file dependency locally (from the Jenkins archive of the upstream dependency just built).

Clever solution with issues:
I clever way to override the external (Artifactory) dependency with my local file is add this code block AFTER the dependencies {} closure in the build.gradle

configurations.each { config ->
    fileTree(dir: 'jenkinsArchives', include: '**/*.jar').each { archive ->
        if(config.dependencies.each { dependency ->
                println "Override ${}"
                config.exclude module:
                dependencies.add(, files(archive))

This works great, however I have about 100 Gradle projects. I would prefer to put this in a plugin, and then use my parent Gradle project to configure an “allprojects { apply plugin: ‘override-plugin’ }”


This code has to run essentially at the end of every Gradle subproject build.gradle. After all the dependencies have been declared but not resolved… beforeEvaluate() runs too early, and afterEvaluate() wont let me change the configurations (can’t add dependencies or exclude configs). I need something sort of in between.

Any suggestions??

I dont want to edit 100’s of Gradle files adding an apply at the end of them (and some subprojects dont even have build.gradle files since they are configured by the subprojects closures)…

FYI: I do use --include-build locally its awesome for testing downstream stuff. But our environment is too complex for me to have Jenkins have some massive matrix of jobs when knowing what SCMs to clone together to test their downstream dependencies when testing patches…

1 Like