-
-
Save matthiasbalke/3c9ecccbea1d460ee4c3fbc5843ede4a to your computer and use it in GitHub Desktop.
// found here: http://jdpgrailsdev.github.io/blog/2014/10/28/gradle_resolve_all_dependencies.html | |
task resolveDependencies { | |
doLast { | |
project.rootProject.allprojects.each { subProject -> | |
subProject.buildscript.configurations.each { configuration -> | |
resolveConfiguration(configuration) | |
} | |
subProject.configurations.each { configuration -> | |
resolveConfiguration(configuration) | |
} | |
} | |
} | |
} | |
void resolveConfiguration(configuration) { | |
if (isResolveableConfiguration(configuration)) { | |
configuration.resolve() | |
} | |
} | |
boolean isResolveableConfiguration(configuration) { | |
def nonResolveableConfigurations = ['apiElements', 'implementation', | |
'runtimeElements', 'runtimeOnly', | |
'testImplementation', 'testRuntimeOnly', | |
'generatedImplementation', 'generatedRuntimeOnly'] | |
if (nonResolveableConfigurations.contains(configuration.getName())) { | |
return false | |
} | |
return true | |
} |
Hi @copitz, thx for letting me know. I didn't know about this alternative approach! Looks promising, I'll test it next time I need this. 👍
Hi, @matthiasbalke what do you think about this one: https://stackoverflow.com/a/47107135/2906505 ? Any pitfalls?
Hi, @dhasilin in my opinion gradle dependencies
does not download all dependencies for all subprojects, but I'm not sure. Maybe I didn't know about that task back in the days.
If you're curious just rename your ~/.gradle
directory then use gradle dependencies
. Afterwards rename it again and use my script. This way you can compare the outcome of the two methods by comparing the generated ~/.gradle
directories.
FYI: a Kotlin version of the code snippet of @copitz:
tasks.register<Task>(name = "resolveDependencies") {
group = "Build Setup"
description = "Resolve and prefetch dependencies"
doLast {
rootProject.allprojects.forEach {
it.buildscript.configurations.filter(Configuration::isCanBeResolved).forEach { it.resolve() }
it.configurations.filter(Configuration::isCanBeResolved).forEach { it.resolve() }
}
}
}
@dirkbolte thanks for sharing this! 👍
When you have other configurations this won't work - here's a solution working with any configuration using Configuration::isCanBeResolved: