Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feasible to add a Gradle task? #6

Open
Montana opened this issue Dec 11, 2021 · 0 comments
Open

Feasible to add a Gradle task? #6

Montana opened this issue Dec 11, 2021 · 0 comments

Comments

@Montana
Copy link

Montana commented Dec 11, 2021

Hey all,

Would it be feasible to add a a Gradle task that prints total dependencies size and (dependency+(size in kb)) list sorted by size desc?

Something like:

asks.register("depsize") {
    description = 'Prints dependencies for "default" configuration'
    doLast() {
        listConfigurationDependencies(configurations.default)
    }
}

tasks.register("depsize-all-configurations") {
    description = 'Prints dependencies for all available configurations'
    doLast() {
        configurations
                .findAll { it.isCanBeResolved() }
                .each { listConfigurationDependencies(it) }
    }
}

def listConfigurationDependencies(Configuration configuration) {
    def formatStr = "%,10.2f"

    def size = configuration.collect { it.length() / (1024 * 1024) }.sum()

    def out = new StringBuffer()
    out << "\nConfiguration name: \"${configuration.name}\"\n"
    if (size) {
        out << 'Total dependencies size:'.padRight(65)
        out << "${String.format(formatStr, size)} Mb\n\n"

        configuration.sort { -it.length() }
                .each {
                    out << "${it.name}".padRight(65)
                    out << "${String.format(formatStr, (it.length() / 1024))} kb\n"
                }
    } else {
        out << 'No dependencies found';
    }
    println(out)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant