Last active
October 20, 2024 11:40
-
-
Save matthiasbalke/3c9ecccbea1d460ee4c3fbc5843ede4a to your computer and use it in GitHub Desktop.
Gradle resolveDependencies Task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, @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! ๐
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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. ๐