Skip to content

Instantly share code, notes, and snippets.

@joshafeinberg
Last active July 27, 2022 04:20
Show Gist options
  • Save joshafeinberg/30828d27c5ac6bf85c9eea8fcc135510 to your computer and use it in GitHub Desktop.
Save joshafeinberg/30828d27c5ac6bf85c9eea8fcc135510 to your computer and use it in GitHub Desktop.
Using Version Catalogs with Dependency Analysis Plugin
ext.reversedMap = [:] as Map<String, String>
void buildReversedMap(String versionCatalogName) {
def versionCatalog = rootProject.extensions
.getByType(VersionCatalogsExtension).named(versionCatalogName)
reversedMap = versionCatalog.getDependencyAliases()
.collectEntries { alias ->
def versionCatalogAlias = "${versionCatalogName}.${alias}"
def module = versionCatalog.findDependency(alias).get().get()
def fullModuleName = "${module.getModule()}:${module.getVersionConstraint()}"
[(fullModuleName.toString()): versionCatalogAlias.toString()]
}
}
buildReversedMap("libs")
dependencyAnalysis {
dependencies {
map.set(reversedMap)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment