From 3fac82742af761cfe16f471d17e2759a9f4da1c9 Mon Sep 17 00:00:00 2001
From: hizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Date: Fri, 19 Apr 2024 18:32:58 +0900
Subject: [PATCH] Use version catalog (#36)

* add catalog toml file

* change declaration for matching catalog definition

* fix dependabot configuration for pointing new toml file
---
 .github/dependabot.yml    |  2 +-
 build.gradle.kts          | 32 +++++++++++++++-----------------
 gradle/libs.versions.toml | 28 ++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 18 deletions(-)
 create mode 100644 gradle/libs.versions.toml

diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 3e4a382..a7357c0 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -6,6 +6,6 @@
 version: 2
 updates:
   - package-ecosystem: "gradle" # See documentation for possible values
-    directory: "/" # Location of package manifests
+    directory: "/gradle/" # Location of package manifests
     schedule:
       interval: "weekly"
diff --git a/build.gradle.kts b/build.gradle.kts
index aa86c50..5f5f4b9 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,11 +1,11 @@
 plugins {
     java
     application
-    id("org.beryx.jlink") version "3.0.1"
-    id("org.openjfx.javafxplugin") version "0.1.0"
-    id("org.javamodularity.moduleplugin") version "1.8.15"
+    alias(libs.plugins.jlink)
+    alias(libs.plugins.moduleplugin)
+    alias(libs.plugins.shadow)
+    alias(libs.plugins.javafxpugin)
     id("org.jetbrains.kotlin.jvm")
-    id("com.github.johnrengelman.shadow") version "8.1.1"
 }
 
 group = "io.github.hizumiaoba"
@@ -40,28 +40,26 @@ javafx {
 }
 
 dependencies {
-    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
+    implementation(libs.kotlin.stdlib)
 
-    implementation("ch.qos.logback:logback-classic:1.5.5")
-    implementation("com.google.guava:guava:33.1.0-jre")
+    implementation(libs.logback)
+    implementation(libs.guava)
     // https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc
-    implementation("org.xerial:sqlite-jdbc:3.45.2.0")
-    implementation("org.projectlombok:lombok:${lombokVersion}")
+    implementation(libs.sqlite.jdbc)
+    implementation(libs.lombok)
     // https://mvnrepository.com/artifact/jakarta.annotation/jakarta.annotation-api
-    implementation("jakarta.annotation:jakarta.annotation-api:${jakartaVersion}")
+    implementation(libs.jakarta.annotation)
     // https://mvnrepository.com/artifact/com.melloware/jintellitype
-    implementation("com.melloware:jintellitype:1.4.1")
+    implementation(libs.jintelitype)
 
 
     // test dependencies
-    testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
-    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
-    testImplementation("com.google.truth:truth:1.4.2")
+    testImplementation(libs.bundles.testlibs)
+    testRuntimeOnly(libs.jupiter.engine)
 
     // annotation processor
-    annotationProcessor("org.projectlombok:lombok:${lombokVersion}")
-    testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}")
-    annotationProcessor("jakarta.annotation:jakarta.annotation-api:${jakartaVersion}")
+    annotationProcessor(libs.bundles.annotationProcess)
+    testAnnotationProcessor(libs.lombok)
 }
 
 tasks.shadowJar {
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
new file mode 100644
index 0000000..9f885d4
--- /dev/null
+++ b/gradle/libs.versions.toml
@@ -0,0 +1,28 @@
+[versions]
+junit = "5.10.1"
+lombok = "1.18.30"
+jakarta = "2.1.1"
+
+[libraries]
+logback = { group = "ch.qos.logback", name = "logback-classic", version = "1.5.5" }
+guava = { group = "com.google.guava", name = "guava", version = "33.1.0-jre" }
+sqlite-jdbc = { group = "org.xerial", name = "sqlite-jdbc", version = "3.45.2.0" }
+lombok = { group = "org.projectlombok", name = "lombok", version.ref = "lombok" }
+jakarta-annotation = { group = "jakarta.annotation", name = "jakarta.annotation-api", version.ref = "jakarta" }
+jintelitype = { group = "com.melloware", name = "jintellitype", version = "1.4.1" }
+jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" }
+jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" }
+truth = { group = "com.google.truth", name = "truth", version = "1.4.2" }
+kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk8", version = "1.8.22" }
+
+[bundles]
+# except for engine dependency, which is only needed for running tests
+testlibs = ["jupiter-api", "truth"]
+# convenience bundle for annotationProcessor
+annotationProcess = ["lombok", "jakarta-annotation"]
+
+[plugins]
+jlink = { id = "org.beryx.jlink", version = "3.0.1" }
+javafxpugin = { id = "org.openjfx.javafxplugin", version = "0.1.0" }
+moduleplugin = { id = "org.javamodularity.moduleplugin", version = "1.8.15" }
+shadow = { id = "com.github.johnrengelman.shadow", version = "8.1.1" }