Skip to content

Instantly share code, notes, and snippets.

@matthiasbalke
Last active April 1, 2023 21:53
Show Gist options
  • Save matthiasbalke/3c9ecccbea1d460ee4c3fbc5843ede4a to your computer and use it in GitHub Desktop.
Save matthiasbalke/3c9ecccbea1d460ee4c3fbc5843ede4a to your computer and use it in GitHub Desktop.
Gradle resolveDependencies Task
// 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
}
@matthiasbalke
Copy link
Author

matthiasbalke commented Nov 6, 2019

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.

@dirkbolte
Copy link

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() }
        }
    }
}

@matthiasbalke
Copy link
Author

@dirkbolte thanks for sharing this! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment