From b7d65dffd0cb53b519f87499c3ac2ec4059c0f3f Mon Sep 17 00:00:00 2001 From: Toshihiro Nakamura Date: Mon, 14 Oct 2024 02:53:53 +0900 Subject: [PATCH] Manage library versions in libs.versions.toml --- build.gradle.kts | 46 +++++++++++++----------- doma-kotlin/build.gradle.kts | 2 +- doma-processor/build.gradle.kts | 2 +- doma-slf4j/build.gradle.kts | 4 +-- gradle/libs.versions.toml | 34 ++++++++++++++++++ integration-test-common/build.gradle.kts | 4 +-- integration-test-kotlin/build.gradle.kts | 6 ++-- settings.gradle.kts | 13 +++---- 8 files changed, 72 insertions(+), 39 deletions(-) create mode 100644 gradle/libs.versions.toml diff --git a/build.gradle.kts b/build.gradle.kts index 884aeb00e..5eb24e169 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,12 +2,12 @@ plugins { `java-library` `maven-publish` signing - id("com.diffplug.spotless") - id("io.github.gradle-nexus.publish-plugin") - id("net.researchgate.release") - id("org.domaframework.doma.compile") - kotlin("jvm") - kotlin("kapt") + alias(libs.plugins.spotless) + alias(libs.plugins.publish) + alias(libs.plugins.release) + alias(libs.plugins.doma.compile) + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.kapt) } val javaLangVersion: Int = project.properties["javaLangVersion"].toString().toInt() @@ -19,6 +19,10 @@ val integrationTestProjects: List = subprojects.filter { it.name.starts val encoding: String by project val isReleaseVersion = !version.toString().endsWith("SNAPSHOT") +// Retain a reference to rootProject.libs to make the version catalog accessible within allprojects and subprojects. +// See https://github.com/gradle/gradle/issues/16708 +val catalog = libs + fun replaceVersionInArtifact(ver: String) { ant.withGroovyBuilder { "replaceregexp"( @@ -64,7 +68,7 @@ fun replaceVersionInDocs(ver: String) { allprojects { apply(plugin = "base") - apply(plugin = "com.diffplug.spotless") + apply(plugin = catalog.plugins.spotless.get().pluginId) repositories { mavenCentral() @@ -85,16 +89,16 @@ subprojects { apply(plugin = "java") dependencies { - "testImplementation"("org.junit.jupiter:junit-jupiter-api:5.11.2") - "testRuntimeOnly"("org.junit.jupiter:junit-jupiter-engine:5.11.2") + testImplementation(catalog.junit.jupiter.api) + testRuntimeOnly(catalog.junit.jupiter.engine) } spotless { java { - googleJavaFormat("1.23.0") + googleJavaFormat(catalog.google.java.format.get().version) } kotlin { - ktlint("0.48.2") + ktlint(catalog.ktlint.get().version) trimTrailingWhitespace() endWithNewline() } @@ -208,16 +212,16 @@ configure(integrationTestProjects) { apply(plugin = "org.domaframework.doma.compile") dependencies { - testImplementation(platform("org.testcontainers:testcontainers-bom:1.20.2")) - testRuntimeOnly("com.h2database:h2:2.3.232") - testRuntimeOnly("mysql:mysql-connector-java:8.0.33") - testRuntimeOnly("com.oracle.database.jdbc:ojdbc11-production:23.5.0.24.07") - testRuntimeOnly("org.postgresql:postgresql:42.7.4") - testRuntimeOnly("com.microsoft.sqlserver:mssql-jdbc:12.8.1.jre11") - testRuntimeOnly("org.testcontainers:mysql") - testRuntimeOnly("org.testcontainers:oracle-xe") - testRuntimeOnly("org.testcontainers:postgresql") - testRuntimeOnly("org.testcontainers:mssqlserver") + testImplementation(platform(catalog.testcontainers.bom)) + testRuntimeOnly(catalog.jdbc.h2) + testRuntimeOnly(catalog.jdbc.mysql) + testRuntimeOnly(catalog.jdbc.oracle) + testRuntimeOnly(catalog.jdbc.postgresql) + testRuntimeOnly(catalog.jdbc.sqlserver) + testRuntimeOnly(catalog.testcontainers.mysql) + testRuntimeOnly(catalog.testcontainers.oracle) + testRuntimeOnly(catalog.testcontainers.postgresql) + testRuntimeOnly(catalog.testcontainers.sqlserver) } java { diff --git a/doma-kotlin/build.gradle.kts b/doma-kotlin/build.gradle.kts index 70bde2dbb..b8661d84f 100644 --- a/doma-kotlin/build.gradle.kts +++ b/doma-kotlin/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - kotlin("jvm") apply true + alias(libs.plugins.kotlin.jvm) } description = "doma-kotlin" diff --git a/doma-processor/build.gradle.kts b/doma-processor/build.gradle.kts index 6da02ae8b..e8e3363bb 100644 --- a/doma-processor/build.gradle.kts +++ b/doma-processor/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("com.github.johnrengelman.shadow") version "8.1.1" + alias(libs.plugins.shadow) } description = "doma-processor" diff --git a/doma-slf4j/build.gradle.kts b/doma-slf4j/build.gradle.kts index 2bf7f7cdb..8c32e1388 100644 --- a/doma-slf4j/build.gradle.kts +++ b/doma-slf4j/build.gradle.kts @@ -1,7 +1,7 @@ description = "doma-slf4j" dependencies { - api("org.slf4j:slf4j-api:2.0.16") + api(libs.slf4j.api) implementation(project(":doma-core")) - testImplementation("ch.qos.logback:logback-classic:1.5.10") + testImplementation(libs.logback.classic) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 000000000..b560d5861 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,34 @@ +[versions] +kotlin = "2.0.21" +junit = "5.11.2" + +[libraries] +jdbc-h2 = { module = "com.h2database:h2", version = "2.3.232" } +jdbc-mysql = { module = "mysql:mysql-connector-java", version = "8.0.33" } +jdbc-oracle = { module = "com.oracle.database.jdbc:ojdbc11", version = "21.15.0.0" } +jdbc-postgresql = { module = "org.postgresql:postgresql", version = "42.7.4" } +jdbc-sqlserver = { module = "com.microsoft.sqlserver:mssql-jdbc", version = "12.8.1.jre11" } + +slf4j-api = { module = "org.slf4j:slf4j-api", version = "2.0.16" } +logback-classic = { module = "ch.qos.logback:logback-classic", version = "1.5.10" } + +junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" } +junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" } + +testcontainers-bom = { module = "org.testcontainers:testcontainers-bom", version = "1.20.2" } +testcontainers-mysql = { module = "org.testcontainers:mysql" } +testcontainers-oracle = { module = "org.testcontainers:oracle-xe" } +testcontainers-postgresql = { module = "org.testcontainers:postgresql" } +testcontainers-sqlserver = { module = "org.testcontainers:mssqlserver" } + +google-java-format = { module = "com.google.googlejavaformat:google-java-format", version = "1.23.0" } +ktlint = { module = "com.pinterest.ktlint:ktlint-cli", version = "0.48.2" } + +[plugins] +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } +spotless = { id = "com.diffplug.spotless", version = "6.25.0" } +publish = { id = "io.github.gradle-nexus.publish-plugin", version = "2.0.0" } +release = { id = "net.researchgate.release", version = "3.0.2" } +doma-compile = { id = "org.domaframework.doma.compile", version = "3.0.1" } +shadow = { id = "com.github.johnrengelman.shadow", version = "8.1.1" } diff --git a/integration-test-common/build.gradle.kts b/integration-test-common/build.gradle.kts index eee0dabff..1758b0a03 100644 --- a/integration-test-common/build.gradle.kts +++ b/integration-test-common/build.gradle.kts @@ -6,6 +6,6 @@ dependencies { annotationProcessor(project(":doma-processor")) implementation(project(":doma-core")) implementation(project(":doma-slf4j")) - implementation("ch.qos.logback:logback-classic:1.5.10") - implementation("org.junit.jupiter:junit-jupiter-api:5.11.2") + implementation(libs.logback.classic) + implementation(libs.junit.jupiter.api) } diff --git a/integration-test-kotlin/build.gradle.kts b/integration-test-kotlin/build.gradle.kts index 49de28874..6900523ea 100644 --- a/integration-test-kotlin/build.gradle.kts +++ b/integration-test-kotlin/build.gradle.kts @@ -1,8 +1,6 @@ -import org.jetbrains.kotlin.platform.jvm.JvmPlatforms - plugins { - kotlin("jvm") - kotlin("kapt") + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.kapt) } dependencies { diff --git a/settings.gradle.kts b/settings.gradle.kts index b6bd2dbeb..5aba9401b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -2,14 +2,11 @@ pluginManagement { repositories { gradlePluginPortal() } - plugins { - id("com.diffplug.eclipse.apt") version "4.1.0" - id("com.diffplug.spotless") version "6.25.0" - id("io.github.gradle-nexus.publish-plugin") version "2.0.0" - id("net.researchgate.release") version "3.0.2" - id("org.domaframework.doma.compile") version "3.0.1" - kotlin("jvm") version "2.0.21" - kotlin("kapt") version "2.0.21" +} + +dependencyResolutionManagement { + versionCatalogs { + create("libs") } }