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.