From 4284385127953a42931f4994dfc8535f6aae8b0c Mon Sep 17 00:00:00 2001 From: Flavio Soibelmann Glock Date: Fri, 2 Jan 2026 09:51:15 +0100 Subject: [PATCH] Migrate to Gradle version catalogs for configuration cache compatibility - Replace ben-manes.versions and use-latest-versions plugins with nl.littlerobots.version-catalog-update - Create gradle/libs.versions.toml for centralized dependency management - Update build.gradle to use version catalog references (libs.*) - Update Configure.pl to use versionCatalogUpdate command - Update .gitignore to track libs.versions.toml - Move DEPENDENCY_UPDATES.md to dev/design/ with updated documentation Benefits: - Full configuration cache compatibility (no need to disable features) - Cleaner, more maintainable dependency management - Type-safe dependency references with IDE autocomplete - Modern Gradle best practice approach --- .gitignore | 3 +- Configure.pl | 6 +-- build.gradle | 47 +++++++++++------- dev/design/DEPENDENCY_UPDATES.md | 82 ++++++++++++++++++++++++++++++++ gradle/libs.versions.toml | 28 +++++++++++ 5 files changed, 144 insertions(+), 22 deletions(-) create mode 100644 dev/design/DEPENDENCY_UPDATES.md create mode 100644 gradle/libs.versions.toml diff --git a/.gitignore b/.gitignore index a9a24c530..e424fb4ca 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,8 @@ target/ .java-version build/ bin/ -gradle/ +gradle/* +!gradle/libs.versions.toml gradlew gradlew.bat .idea/ diff --git a/Configure.pl b/Configure.pl index 794e1e025..a70a84c04 100755 --- a/Configure.pl +++ b/Configure.pl @@ -269,10 +269,10 @@ sub update_to_latest_versions { } } - # Update Gradle dependencies + # Update Gradle dependencies using version catalog if (-f 'build.gradle') { - print "Updating Gradle dependencies to latest versions...\n"; - my $gradle_output = `./gradlew useLatestVersions`; + print "Updating Gradle dependencies to latest versions using version catalog...\n"; + my $gradle_output = `./gradlew versionCatalogUpdate`; my $gradle_status = $? >> 8; if ($gradle_status != 0) { warn "Failed to update Gradle dependencies. Exit status: $gradle_status\n"; diff --git a/build.gradle b/build.gradle index ac4dd988c..7886a9535 100644 --- a/build.gradle +++ b/build.gradle @@ -13,15 +13,13 @@ buildscript { // Core plugins configuration plugins { id 'java' - // Plugin for checking dependency updates - id 'com.github.ben-manes.versions' version '0.53.0' - // Plugin for automatically updating dependencies - id 'se.patrikerdes.use-latest-versions' version '0.2.19' + // Plugin for updating version catalog with latest versions (configuration cache compatible!) + alias(libs.plugins.version.catalog.update) id 'application' // Plugin for creating OS packages (deb) - id 'com.netflix.nebula.ospackage' version '12.1.1' + alias(libs.plugins.ospackage) // Plugin for creating fat/uber JARs - id 'com.gradleup.shadow' version '9.3.0' + alias(libs.plugins.shadow) } // Main application class configuration @@ -68,20 +66,20 @@ repositories { // Project dependencies dependencies { // Core dependencies - implementation 'org.ow2.asm:asm:9.9' // ByteCode manipulation - implementation 'org.ow2.asm:asm-util:9.9' // ASM utilities - implementation 'com.ibm.icu:icu4j:78.1' // Unicode support - implementation 'com.alibaba.fastjson2:fastjson2:2.0.60' // JSON processing - implementation 'org.snakeyaml:snakeyaml-engine:3.0.1' // YAML processing - implementation 'org.tomlj:tomlj:1.1.1' // TOML processing - implementation 'org.apache.commons:commons-csv:1.14.1' // CSV processing - implementation 'net.java.dev.jna:jna:5.18.1' // Native access - implementation 'net.java.dev.jna:jna-platform:5.18.1' // Native access + implementation libs.asm // ByteCode manipulation + implementation libs.asm.util // ASM utilities + implementation libs.icu4j // Unicode support + implementation libs.fastjson2 // JSON processing + implementation libs.snakeyaml.engine // YAML processing + implementation libs.tomlj // TOML processing + implementation libs.commons.csv // CSV processing + implementation libs.jna // Native access + implementation libs.jna.platform // Native access // Testing dependencies - testImplementation 'org.junit.jupiter:junit-jupiter-api:6.1.0-M1' - testImplementation 'org.junit.jupiter:junit-jupiter-engine:6.1.0-M1' - testImplementation 'org.junit.jupiter:junit-jupiter-params:6.1.0-M1' + testImplementation libs.junit.jupiter.api + testImplementation libs.junit.jupiter.engine + testImplementation libs.junit.jupiter.params } // JUnit configuration @@ -220,3 +218,16 @@ tasks.register('testUnitParallel') { description = 'Runs unit tests in parallel across multiple JVMs. Usage: gradle testUnitParallel --parallel' dependsOn 'testUnitShard0', 'testUnitShard1', 'testUnitShard2', 'testUnitShard3' } + +// Version catalog update configuration +// The nl.littlerobots.version-catalog-update plugin is configuration cache compatible! +// Use: ./gradlew versionCatalogUpdate to check and update dependencies +// Use: ./gradlew versionCatalogUpdate --interactive to review changes interactively +versionCatalogUpdate { + // Sort the catalog keys + sortByKey = true + // Keep versions not used in the project + keep { + keepUnusedVersions = true + } +} diff --git a/dev/design/DEPENDENCY_UPDATES.md b/dev/design/DEPENDENCY_UPDATES.md new file mode 100644 index 000000000..a5b506b1f --- /dev/null +++ b/dev/design/DEPENDENCY_UPDATES.md @@ -0,0 +1,82 @@ +# Dependency Management Guide + +This project uses **Gradle Version Catalogs** for centralized dependency management. All dependencies are defined in `gradle/libs.versions.toml`. + +## Benefits of Version Catalogs + +- **Centralized Management**: All versions in one place (`gradle/libs.versions.toml`) +- **Type-Safe**: IDE autocomplete for dependencies +- **Configuration Cache Compatible**: Works with Gradle's configuration cache for faster builds +- **Easy Updates**: Simple commands to check and update dependencies + +## Available Tasks + +### Check and Update Dependencies + +```bash +# Check for updates and automatically update the version catalog +./gradlew versionCatalogUpdate +``` + +This will: +- Check all dependencies for newer versions +- Update `gradle/libs.versions.toml` with the latest versions +- Maintain proper formatting + +### Interactive Mode + +```bash +# Review each update interactively before applying +./gradlew versionCatalogUpdate --interactive +``` + +### Format Version Catalog + +```bash +# Format the libs.versions.toml file (fully configuration cache compatible) +./gradlew versionCatalogFormat +``` + +## Version Catalog Location + +All dependencies are defined in: `gradle/libs.versions.toml` + +Structure: +- `[versions]` - Version numbers +- `[libraries]` - Library dependencies +- `[plugins]` - Gradle plugins + +## Adding New Dependencies + +1. Add the version to `[versions]` section +2. Add the library reference to `[libraries]` section +3. Use in `build.gradle` with: `implementation libs.library.name` + +Example: +```toml +[versions] +gson = "2.10.1" + +[libraries] +gson = { module = "com.google.code.gson:gson", version.ref = "gson" } +``` + +Then in `build.gradle`: +```groovy +dependencies { + implementation libs.gson +} +``` + +## Important Notes + +- **Configuration Cache**: Fully compatible! No need to disable features +- **Review Changes**: Always review updates before committing +- **Test After Updates**: Run `./gradlew clean build test` after updating +- **Pin Versions**: Add `# @pin` comment in TOML to prevent auto-updates + +## Migration Complete + +✅ Migrated from `ben-manes.versions` + `use-latest-versions` to version catalogs +✅ Configuration cache now works with all tasks +✅ Cleaner, more maintainable dependency management diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 000000000..6112f8a4b --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,28 @@ +[versions] +asm = "9.9.1" +commons-csv = "1.14.1" +fastjson2 = "2.0.60" +icu4j = "78.1" +jna = "5.18.1" +junit-jupiter = "6.1.0-M1" +snakeyaml-engine = "3.0.1" +tomlj = "1.1.1" + +[libraries] +asm = { module = "org.ow2.asm:asm", version.ref = "asm" } +asm-util = { module = "org.ow2.asm:asm-util", version.ref = "asm" } +commons-csv = { module = "org.apache.commons:commons-csv", version.ref = "commons-csv" } +fastjson2 = { module = "com.alibaba.fastjson2:fastjson2", version.ref = "fastjson2" } +icu4j = { module = "com.ibm.icu:icu4j", version.ref = "icu4j" } +jna = { module = "net.java.dev.jna:jna", version.ref = "jna" } +jna-platform = { module = "net.java.dev.jna:jna-platform", version.ref = "jna" } +junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-jupiter" } +junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-jupiter" } +junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit-jupiter" } +snakeyaml-engine = { module = "org.snakeyaml:snakeyaml-engine", version.ref = "snakeyaml-engine" } +tomlj = { module = "org.tomlj:tomlj", version.ref = "tomlj" } + +[plugins] +ospackage = "com.netflix.nebula.ospackage:12.1.1" +shadow = "com.gradleup.shadow:9.3.0" +version-catalog-update = "nl.littlerobots.version-catalog-update:1.0.1"