Can I set changing = true for a dependency in afterEvaluate?

I would like to run something like this

afterEvaluate { project ->
    project.configurations
            .collectMany { it.allDependencies }
            .findAll { it instanceof ExternalModuleDependency && it.group.startsWith("com.my-company") }
            .each {
                it.changing = true
            }
}

Gradle does not complain, but I wondered if it is too late to do so ? When does Gradle check if it needs to re-download the version (given that cacheChangingModulesFor is set to 0 seconds)

I’m not an expert on the Gradle internals, but I’d say that the check is performed when the configuration is resolved. I expect your code to be fine, unless something triggers the resolution of a configuration during the evaluation phase. I think in that case your code may throw an error, but I’m not sure. You could test it out by forcing a configuration to resolve during evaluation with a simple command outside your afterEvaluate closure.

println configurations.pickOneYourProjectHas.join( '\n' )
afterEvaluate { project ->
    ...
}

It should print out a list of resolved files and then possibly throw an error when it tries to change the dependencies.