Skip to content

Commit eec781e

Browse files
authored
Modernize Gradle configuration (#211)
* feat: Modernize Gradle configuration by introducing version catalogs, setting build properties, and updating Java toolchain.
1 parent daf150d commit eec781e

File tree

5 files changed

+80
-46
lines changed

5 files changed

+80
-46
lines changed

build.gradle

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
plugins {
22
id "java"
3-
id "com.diffplug.spotless" version "6.20.0"
4-
id "net.ltgt.errorprone" version "4.0.1"
5-
id "edu.wpi.first.GradleRIO" version "2025.3.2"
3+
alias(libs.plugins.spotless)
4+
alias(libs.plugins.errorprone)
5+
alias(libs.plugins.wpilib)
66
}
77

88
java {
9-
sourceCompatibility = JavaVersion.VERSION_17
10-
targetCompatibility = JavaVersion.VERSION_17
9+
toolchain {
10+
languageVersion = JavaLanguageVersion.of(17)
11+
}
1112
}
1213

1314
def getProjectBooleanProperty(String name, boolean defaultValue = false) {
@@ -65,7 +66,8 @@ def includeDesktopSupport = true
6566
// Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries.
6667
// Also defines JUnit 5.
6768
dependencies {
68-
compileOnly group: "com.google.errorprone", name: "error_prone_annotations", version: "2.28.0"
69+
errorprone libs.errorprone.core
70+
compileOnly libs.errorprone.annotations
6971

7072
annotationProcessor wpi.java.deps.wpilibAnnotations()
7173
implementation wpi.java.deps.wpilib()
@@ -85,10 +87,8 @@ dependencies {
8587
nativeRelease wpi.java.vendor.jniRelease(wpi.platforms.desktop)
8688
simulationRelease wpi.sim.enableRelease()
8789

88-
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1'
89-
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
90-
91-
errorprone group: "com.google.errorprone", name: "error_prone_core", version: "2.28.0"
90+
testImplementation libs.junit.jupiter
91+
testRuntimeOnly libs.junit.platform.launcher
9292
}
9393

9494
test {

buildinfo.gradle

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import java.net.InetAddress;
22

33
task writeBuildInfo {
4-
def hasGit = { ->
5-
try {
6-
exec {
7-
executable 'git'
8-
delegate.args '--version'
9-
standardOutput = OutputStream.nullOutputStream()
10-
}
11-
} catch (Exception e) {
12-
return false
13-
}
14-
return true
15-
}
4+
def hasGit = { ->
5+
try {
6+
def result = exec {
7+
executable 'git'
8+
args '--version'
9+
standardOutput = OutputStream.nullOutputStream()
10+
ignoreExitValue = true
11+
}
12+
return result.exitValue == 0
13+
} catch (Exception e) {
14+
return false
15+
}
16+
}
1617

1718
def addGitOutput = { PrintStream output, String name, String... args ->
1819
output.println("### $name (git ${String.join(' ', args)})")
@@ -39,30 +40,30 @@ task writeBuildInfo {
3940
return path
4041
}
4142

42-
doLast {
43-
try (PrintStream output = new PrintStream('src/main/deploy/build-info.txt')) {
44-
output.println("### Host name (InetAddress.localHost.hostName)")
45-
output.println(InetAddress.localHost.hostName)
46-
output.println("### Project path (convertPath(projectDir.path))")
47-
output.println(convertPath(projectDir.path))
48-
if (!hasGit()) {
49-
// ANSI escape codes
50-
def WARNINGFMT = "\033[43;30m"
51-
def CLEAR = "\033[m"
52-
println("${WARNINGFMT}WARNING: Could not find git! Git info will not be sent to the robot.${CLEAR}")
53-
output.println("### <could not run git>")
54-
} else {
55-
addGitOutput(output, 'Commit hash', 'log', '-1', '--format=%H')
56-
addGitOutput(output, 'Refs to latest commit', 'log', '-1', '--format=%D')
57-
addGitOutput(output, 'Commit time', 'log', '-1', '--format=%ad')
58-
addGitOutput(output, 'Commit message', 'log', '-1', '--format=%B')
59-
addGitOutput(output, 'Remotes', 'remote', '-v')
60-
addGitOutput(output, 'Changed files', 'diff-index', '--name-only', 'HEAD', '--')
61-
addGitOutput(output, 'Untracked files', 'ls-files', '--exclude-standard', '--others')
62-
}
63-
output.println('### (END)')
64-
}
65-
}
43+
doLast {
44+
new PrintStream('src/main/deploy/build-info.txt').withStream { output ->
45+
output.println("### Host name (InetAddress.localHost.hostName)")
46+
output.println(InetAddress.localHost.hostName)
47+
output.println("### Project path (convertPath(projectDir.path))")
48+
output.println(convertPath(projectDir.path))
49+
if (!hasGit()) {
50+
// ANSI escape codes
51+
def WARNINGFMT = "\033[43;30m"
52+
def CLEAR = "\033[m"
53+
println("${WARNINGFMT}WARNING: Could not find git! Git info will not be sent to the robot.${CLEAR}")
54+
output.println("### <could not run git>")
55+
} else {
56+
addGitOutput(output, 'Commit hash', 'log', '-1', '--format=%H')
57+
addGitOutput(output, 'Refs to latest commit', 'log', '-1', '--format=%D')
58+
addGitOutput(output, 'Commit time', 'log', '-1', '--format=%ad')
59+
addGitOutput(output, 'Commit message', 'log', '-1', '--format=%B')
60+
addGitOutput(output, 'Remotes', 'remote', '-v')
61+
addGitOutput(output, 'Changed files', 'diff-index', '--name-only', 'HEAD', '--')
62+
addGitOutput(output, 'Untracked files', 'ls-files', '--exclude-standard', '--others')
63+
}
64+
output.println('### (END)')
65+
}
66+
}
6667
}
6768
if (getProjectBooleanProperty('jarWriteBuildInfo', true)) {
6869
jar.dependsOn(writeBuildInfo)

gradle.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Enable build caching
2+
org.gradle.caching=true
3+
# Enable parallel execution
4+
org.gradle.parallel=true
5+
# Configure JVM memory
6+
org.gradle.jvmargs=-Xmx2g

gradle/libs.versions.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[versions]
2+
wpilib = "2025.3.2"
3+
spotless = "6.20.0"
4+
errorpronePlugin = "4.0.1"
5+
errorproneCore = "2.28.0"
6+
errorproneAnnotations = "2.28.0"
7+
junit = "5.10.1"
8+
junitPlatform = "1.10.1"
9+
10+
[libraries]
11+
wpilib-java = { module = "edu.wpi.first.gradle:edu.wpi.first.gradle.gradle.plugin", version.ref = "wpilib" }
12+
spotless-plugin = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" }
13+
errorprone-plugin = { module = "net.ltgt.gradle:gradle-errorprone-plugin", version.ref = "errorpronePlugin" }
14+
15+
errorprone-annotations = { module = "com.google.errorprone:error_prone_annotations", version.ref = "errorproneAnnotations" }
16+
errorprone-core = { module = "com.google.errorprone:error_prone_core", version.ref = "errorproneCore" }
17+
18+
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
19+
junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junitPlatform" }
20+
[plugins]
21+
wpilib = { id = "edu.wpi.first.GradleRIO", version.ref = "wpilib" }
22+
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
23+
errorprone = { id = "net.ltgt.errorprone", version.ref = "errorpronePlugin" }

settings.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@ pluginManagement {
2626
}
2727
}
2828

29+
plugins {
30+
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
31+
}
32+
2933
Properties props = System.getProperties();
3034
props.setProperty("org.gradle.internal.native.headers.unresolved.dependencies.ignore", "true");

0 commit comments

Comments
 (0)