All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vgaidarji.dependencies.overview.ArtifactsResolver.kt Maven / Gradle / Ivy

Go to download

Generates project dependencies overview report (JSON, Markdown, etc.) from project dependencies

There is a newer version: 1.0.1
Show newest version
package com.vgaidarji.dependencies.overview

import org.gradle.api.Project
import org.gradle.api.artifacts.ResolvedModuleVersion

/**
 * Default project configuration from where artifacts will be resolved.
 */
const val DEFAULT_CONFIGURATION = "compile"

/**
 * Resolves artifacts for given project.
 */
class ArtifactsResolver(var project: Project) {
    /**
     * Resolves artifacts list for given configuration.
     * @param configuration default value is "compile" configuration
     */
    fun resolve(configuration: String = DEFAULT_CONFIGURATION): List {
        val artifacts = mutableListOf()
        val config = project.configurations.getByName(configuration).resolvedConfiguration
        config.resolvedArtifacts.forEach {
            artifacts.add(it.moduleVersion)
        }
        return sortArtifacts(artifacts)
    }

    /**
     * Sorts given artifacts list by artifact group and name.
     */
    private fun sortArtifacts(artifacts: List): List {
        return artifacts.sortedWith(compareBy({ it.id.group }, { it.id.name }))
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy