-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publish a version catalog alongside the BOM
This commit introduces a new artifact published alongside the BOM: a Gradle _version catalog_. A version catalog is not a replacement for a BOM. It can be seen as an alternative, or a complement to a BOM file. For example, a user can import the Micronaut version catalog in their settings file by doing: ```gradle dependencyResolutionManagement { versionCatalogs { create("mn") { from("io.micronaut:micronaut-bom:3.0.1-SNAPSHOT") } } } ``` Gradle will then generate _version accessors_, which allows replacing dependency notations from: ```gradle implementation "ch.qos.logback:logback-classic" ``` to: ```gradle implementation mn.logback ``` Those accessors are _type safe_. Version catalogs should really be seen as "recommendations". Without applying a BOM in addition, the versions declared in a catalog have _no impact_ on dependency resolution. Therefore, it is often recommended to apply both the BOM _and_ use catalogs to declare dependencies. It comes with an advantage, which is that versions declared in the BOM can be overridden by the user: ```gradle dependencyResolutionManagement { versionCatalogs { create("mn") { from("io.micronaut:micronaut-bom:3.0.1-SNAPSHOT") version("snakeyaml") { strictly("1.28") } } } } ```
- Loading branch information
Showing
3 changed files
with
110 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
plugins { | ||
id 'groovy-gradle-plugin' | ||
} | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
} | ||
|
||
dependencies { | ||
implementation "io.micronaut.build.internal:micronaut-gradle-plugins:4.1.0-SNAPSHOT" | ||
implementation "org.tomlj:tomlj:1.0.0" | ||
} |
64 changes: 64 additions & 0 deletions
64
buildSrc/src/main/groovy/io/micronaut/build/internal/pom/VersionCatalogConverter.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.micronaut.build.internal.pom | ||
|
||
import groovy.transform.Canonical | ||
import io.micronaut.build.catalogs.internal.LenientVersionCatalogParser | ||
import org.gradle.api.plugins.catalog.CatalogPluginExtension | ||
import org.gradle.api.tasks.TaskAction | ||
/** | ||
* This is an internal task which responsibility is to parse | ||
* the Micronaut version catalog used internally, extract components | ||
* which belong to the BOM, in order to populate the version catalog | ||
* model for Gradle. | ||
* | ||
* In the end, this model is used to generate a version catalog in | ||
* addition to the bom. This will let users choose between importing | ||
* a BOM or using the Micronaut version catalog. | ||
* | ||
*/ | ||
@Canonical | ||
class VersionCatalogConverter { | ||
final File catalogFile | ||
final CatalogPluginExtension catalogExtension | ||
final Map<String, String> extraVersions = [:] | ||
final Map<String, Library> extraLibraries = [:] | ||
|
||
@TaskAction | ||
void populateModel() { | ||
def parser = new LenientVersionCatalogParser() | ||
parser.parse(catalogFile.newInputStream()) | ||
def model = parser.model | ||
catalogExtension.versionCatalog {builder -> | ||
extraVersions.forEach { alias, version -> | ||
builder.version(alias, version) | ||
} | ||
extraLibraries.forEach { alias, library -> | ||
builder.alias(alias) | ||
.to(library.group, library.name) | ||
.versionRef(library.versionRef) | ||
} | ||
model.versionsTable.each { version -> | ||
if (version.reference.startsWith('managed-')) { | ||
builder.version(version.reference.substring(8), version.version.require) | ||
} | ||
} | ||
model.librariesTable.each { library -> | ||
if (library.alias.startsWith("managed-") && library.version.reference) { | ||
builder.alias(library.alias.substring(8)) | ||
.to(library.group, library.name) | ||
.versionRef(library.version.reference.substring(8)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
static Library library(String group, String name, String versionRef) { | ||
new Library(group, name, versionRef) | ||
} | ||
|
||
@Canonical | ||
static class Library { | ||
final String group | ||
final String name | ||
final String versionRef | ||
} | ||
} |