Matthew Inger
03/31/2022, 8:51 PMVampire
03/31/2022, 8:54 PMgrossws
03/31/2022, 9:09 PMfun DependencyHandler.derivePlatformFromCatalog(catalog: VersionCatalog) =
derivePlatformFromCatalog(catalog) { "api" }
fun DependencyHandler.derivePlatformFromCatalog(catalog: VersionCatalog, classifier: (String) -> String): Unit = run {
catalog.libraryAliases.filter { it.endsWith(".bom") }.forEach { alias ->
val library = catalog.getLibrary(alias).get()
if (library.versioned) add(classifier(alias), platform(library))
}
catalog.libraryAliases.filterNot { it.endsWith(".bom") }.forEach { alias ->
constraints {
val library = catalog.getLibrary(alias).get()
if (library.versioned) add(classifier(alias), library)
}
}
}
private val MinimalExternalModuleDependency.versioned: Boolean
get() = versionConstraint.requiredVersion.isNotBlank()
|| versionConstraint.strictVersion.isNotBlank()
|| versionConstraint.preferredVersion.isNotBlank()
|| versionConstraint.rejectedVersions.isNotEmpty()
fun VersionCatalog.getLibrary(alias: String): Provider<MinimalExternalModuleDependency> =
findLibrary(alias).orElseThrow { NoSuchElementException("library $alias not found in catalog $name") }
To get version catalog itself just use project.the<VersionCatalogExtension>().named("libs")
grossws
03/31/2022, 9:11 PMbom
as last segment and javaPlaform.allowDependencies()
to import other BOMs/platforms into currentMatthew Inger
03/31/2022, 9:28 PMMatthew Inger
03/31/2022, 9:28 PMbuildscript {
dependencies {
classpath("nl.littlerobots.vcu:plugin:0.3.1")
}
}
val toml = file("gradle/libsExternal.versions.toml").inputStream().use {
VersionCatalogParser().parse(it)
}
val deps = toml.libraries.values.map { library ->
val versionObject = library.resolvedVersion(toml)
val resolved = when (versionObject) {
is nl.littlerobots.vcu.model.VersionDefinition.Simple -> {
versionObject.version
}
else -> {
versionObject.toString()
}
}
"${library.group}:${library.name}:${resolved}"
}
dependencies {
deps.forEach {
implementation(it)
}
}
and then just run the “depenencies” targetVampire
03/31/2022, 9:30 PMMatthew Inger
03/31/2022, 9:43 PMgrossws
03/31/2022, 10:14 PMMatthew Inger
04/01/2022, 3:26 PM