com.vgaidarji.dependencies.overview.ArtifactsResolver.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dependencies-overview Show documentation
Show all versions of dependencies-overview Show documentation
Generates project dependencies overview report (JSON, Markdown, etc.) from project dependencies
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