From 571bc58f8074a1cc91ec1d41837a8d514d048cdc Mon Sep 17 00:00:00 2001 From: JFronny Date: Mon, 22 Apr 2024 11:11:10 +0200 Subject: [PATCH] feat: add version catalog and bom --- README.md | 2 + commons-bom/build.gradle.kts | 55 +++++++++++++++++++++++++++ commons-catalog/build.gradle.kts | 65 ++++++++++++++++++++++++++++++++ settings.gradle.kts | 2 + 4 files changed, 124 insertions(+) create mode 100644 commons-bom/build.gradle.kts create mode 100644 commons-catalog/build.gradle.kts diff --git a/README.md b/README.md index 85d7a6c..89e7f74 100644 --- a/README.md +++ b/README.md @@ -39,3 +39,5 @@ Common code for my java projects. Uses my common [build scripts](https://git.fro - commons-manifold: Some common code using the features of manifold-ext. Mainly extension classes. - commons-gson: Provides some utility classes around my fork of gson and an implementation of the `Serializer` interface - commons-unsafe: Provides wrappers around sun.misc.Unsafe and the LambdaMetaFactory +- commons-bom: A maven BOM to make using multiple modules easier +- commons-catalog: A gradle version catalog to make using multiple modules easier \ No newline at end of file diff --git a/commons-bom/build.gradle.kts b/commons-bom/build.gradle.kts new file mode 100644 index 0000000..1535a49 --- /dev/null +++ b/commons-bom/build.gradle.kts @@ -0,0 +1,55 @@ +plugins { + `java-platform` + `maven-publish` +} + +version = rootProject.version + +publishing { + repositories { + mavenLocal() + + if (project.hasProperty("maven")) { + maven { + url = uri(project.property("maven").toString()) + name = "dynamic" + + credentials(PasswordCredentials::class) { + username = System.getenv()["MAVEN_NAME"] + password = System.getenv()["MAVEN_TOKEN"] + } + authentication { + create("basic") + } + } + } + } + + publications { + create("maven") { + groupId = "io.gitlab.jfronny" + artifactId = "commons-bom" + + from(components["javaPlatform"]) + } + } +} + +tasks.withType(GenerateModuleMetadata::class) { + enabled = true +} + +dependencies { + constraints { + for (proj in rootProject.allprojects) { + if (proj == project || proj == rootProject) { + continue + } + if (proj.name == "commons-catalog") { + continue + } + + api(project(proj.path)) + } + } +} \ No newline at end of file diff --git a/commons-catalog/build.gradle.kts b/commons-catalog/build.gradle.kts new file mode 100644 index 0000000..ddcd199 --- /dev/null +++ b/commons-catalog/build.gradle.kts @@ -0,0 +1,65 @@ +plugins { + `version-catalog` + `maven-publish` +} + +version = rootProject.version + +publishing { + repositories { + mavenLocal() + + if (project.hasProperty("maven")) { + maven { + url = uri(project.property("maven").toString()) + name = "dynamic" + + credentials(PasswordCredentials::class) { + username = System.getenv()["MAVEN_NAME"] + password = System.getenv()["MAVEN_TOKEN"] + } + authentication { + create("basic") + } + } + } + } + + publications { + create("maven") { + groupId = "io.gitlab.jfronny" + artifactId = "commons-catalog" + + from(components["versionCatalog"]) + } + } +} + +tasks.withType(GenerateModuleMetadata::class) { + enabled = true +} + +tasks.register("configureCatalog") { + doFirst { + doConfigureCatalog() + } +} +tasks.named("generateCatalogAsToml") { + dependsOn("configureCatalog") +} + +fun doConfigureCatalog() { + for (proj in rootProject.allprojects) { + if (proj == project || proj == rootProject) { + continue + } + + val catalogName = if (proj.name == "commons-bom") "bom" else proj.name + + catalog { + versionCatalog { + library(catalogName, "$group:${proj.name}:${proj.version}") + } + } + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index a1c6145..80c700e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -31,5 +31,7 @@ include("commons-logger") include("commons-manifold") include("commons-gson") include("commons-unsafe") +include("commons-bom") +include("commons-catalog") enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")