diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 00000000..83faff04 --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,12 @@ +plugins { + id 'groovy-gradle-plugin' +} + +dependencies { + // Spotless code formatter. + implementation('com.diffplug.spotless:com.diffplug.spotless.gradle.plugin:6.25.0') +} + +repositories { + gradlePluginPortal() +} diff --git a/buildSrc/src/main/groovy/java-common-conventions.gradle b/buildSrc/src/main/groovy/java-common-conventions.gradle new file mode 100644 index 00000000..61f351ed --- /dev/null +++ b/buildSrc/src/main/groovy/java-common-conventions.gradle @@ -0,0 +1,50 @@ +plugins { + // Apply the java-library plugin for API and implementation separation. + id 'java-library' + id 'com.diffplug.spotless' +} + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +tasks.withType(JavaCompile) { + // Configure string concat to always inline compile + options.compilerArgs.add '-XDstringConcat=inline' +} + +tasks.named('jar') { + manifest { + attributes( + 'Implementation-Title': project.name, + 'Implementation-Version': project.version, + ) + } +} + +spotless { + // See https://github.com/diffplug/spotless/tree/main/plugin-gradle + format 'misc', { + // define the files to apply `misc` to + target '.gitattributes', '.gitignore' + + // define the steps to apply to those files + trimTrailingWhitespace() + indentWithSpaces() + endWithNewline() + } + groovyGradle { + greclipse().configFile('../greclipse-gradle.properties') + } + java { + importOrder() // Use the default importOrder configuration (can override) + removeUnusedImports() + + // Use Google Java Format + // - aosp() causes it to use a four-space indent + googleJavaFormat('1.24.0').reflowLongStrings() + + formatAnnotations() // fix formatting of type annotations + } +} diff --git a/lib/greclipse-gradle.properties b/greclipse-gradle.properties similarity index 100% rename from lib/greclipse-gradle.properties rename to greclipse-gradle.properties diff --git a/lib/build.gradle b/lib/build.gradle index 0b729b52..a7a1f7a9 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -7,22 +7,9 @@ */ plugins { - // Apply the java-library plugin for API and implementation separation. - id 'java-library' + id 'java-common-conventions' id 'edu.wpi.first.GradleRIO' version '2025.1.1' id 'maven-publish' - // Spotless code formatter. - id 'com.diffplug.spotless' version '6.25.0' -} - -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 -} - -tasks.withType(JavaCompile) { - // Configure string concat to always inline compile - options.compilerArgs.add '-XDstringConcat=inline' } version = '2.0.0-alpha.1' @@ -59,18 +46,11 @@ dependencies { wpi.java.configureTestTasks(test) tasks.named('test') { - // Use JUnit 4 for unit tests. + // Support running both JUnit Vintage and JUnit Jupiter tests useJUnitPlatform() systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true' } -tasks.named('jar') { - manifest { - attributes('Implementation-Title': project.name, - 'Implementation-Version': project.version) - } -} - javadoc { options.tags = [ // Converts `@apiNote` paragraph to "Note: " section in the generated javadoc @@ -80,46 +60,11 @@ javadoc { ] } -// Generates Javadocs for test libraries under /build/docs/testjavadoc -// https://discuss.gradle.org/t/how-configure-gradle-to-generate-javadoc-for-testing-classes-junit/12764/6 -task testJavadoc(type: Javadoc) { - source = sourceSets.test.allJava - classpath = sourceSets.test.compileClasspath - destinationDir = file("${buildDir}/docs/testjavadoc") - println (title == null ? '' : title) -} - task sourceJar(type: Jar) { from sourceSets.main.allJava archiveClassifier = 'sources' } -spotless { - // See https://github.com/diffplug/spotless/tree/main/plugin-gradle - format 'misc', { - // define the files to apply `misc` to - target '.gitattributes', '.gitignore' - - // define the steps to apply to those files - trimTrailingWhitespace() - indentWithSpaces() - endWithNewline() - } - groovyGradle { - greclipse().configFile('greclipse-gradle.properties') - } - java { - importOrder() // Use the default importOrder configuration (can override) - removeUnusedImports() - - // Use Google Java Format - // - aosp() causes it to use a four-space indent - googleJavaFormat('1.24.0').reflowLongStrings() - - formatAnnotations() // fix formatting of type annotations - } -} - publishing { publications { lib2813(MavenPublication) { diff --git a/limelight/build.gradle b/limelight/build.gradle index 3ec00d4c..5b39a260 100644 --- a/limelight/build.gradle +++ b/limelight/build.gradle @@ -1,9 +1,9 @@ plugins { - id 'java-library' + id 'java-common-conventions' id "edu.wpi.first.GradleRIO" version "2025.1.1" id 'idea' // Spotless code formatter. - id 'com.diffplug.spotless' version '6.25.0' + id 'com.diffplug.spotless' } idea { @@ -13,11 +13,6 @@ idea { } } -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 -} - repositories { mavenCentral() } @@ -25,12 +20,13 @@ repositories { dependencies { implementation wpi.java.deps.wpilib() implementation wpi.java.vendor.java() + implementation 'com.google.code.gson:gson:2.12.1' api "org.json:json:20240205" testImplementation 'junit:junit:4.13.2' testImplementation 'com.google.truth:truth:1.4.4' - implementation 'com.google.code.gson:gson:2.12.1' + testImplementation project(':testing') nativeDebug wpi.java.deps.wpilibJniDebug(wpi.platforms.desktop) nativeDebug wpi.java.vendor.jniDebug(wpi.platforms.desktop) @@ -47,29 +43,3 @@ tasks.named('test') { // Use JUnit 4 for tests useJUnit() } - -spotless { - // See https://github.com/diffplug/spotless/tree/main/plugin-gradle - format 'misc', { - // define the files to apply `misc` to - target '.gitattributes', '.gitignore' - - // define the steps to apply to those files - trimTrailingWhitespace() - indentWithSpaces() - endWithNewline() - } - groovyGradle { - greclipse().configFile('greclipse-gradle.properties') - } - java { - importOrder() // Use the default importOrder configuration (can override) - removeUnusedImports() - - // Use Google Java Format - // - aosp() causes it to use a four-space indent - googleJavaFormat('1.24.0').reflowLongStrings() - - formatAnnotations() // fix formatting of type annotations - } -} diff --git a/limelight/greclipse-gradle.properties b/limelight/greclipse-gradle.properties deleted file mode 100644 index 9913ef41..00000000 --- a/limelight/greclipse-gradle.properties +++ /dev/null @@ -1 +0,0 @@ -org.eclipse.jdt.core.formatter.tabulation.char=space diff --git a/limelight/src/test/java/com/team2813/lib2813/limelight/LimelightTestCase.java b/limelight/src/test/java/com/team2813/lib2813/limelight/LimelightTestCase.java index 5245c864..8e472fc2 100644 --- a/limelight/src/test/java/com/team2813/lib2813/limelight/LimelightTestCase.java +++ b/limelight/src/test/java/com/team2813/lib2813/limelight/LimelightTestCase.java @@ -2,9 +2,9 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; -import static com.team2813.lib2813.limelight.truth.Pose2dSubject.assertThat; -import static com.team2813.lib2813.limelight.truth.Pose3dSubject.assertThat; -import static com.team2813.lib2813.limelight.truth.Translation3dSubject.assertThat; +import static com.team2813.lib2813.testing.truth.Pose2dSubject.assertThat; +import static com.team2813.lib2813.testing.truth.Pose3dSubject.assertThat; +import static com.team2813.lib2813.testing.truth.Translation3dSubject.assertThat; import static org.junit.Assert.assertEquals; import edu.wpi.first.math.geometry.Pose2d; diff --git a/settings.gradle b/settings.gradle index fbfcd126..536f46a8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -9,4 +9,5 @@ rootProject.name = 'lib2813' include('lib') -include('limelight') \ No newline at end of file +include('limelight') +include('testing') diff --git a/testing/build.gradle b/testing/build.gradle new file mode 100644 index 00000000..bb4a224b --- /dev/null +++ b/testing/build.gradle @@ -0,0 +1,60 @@ +plugins { + id 'java-common-conventions' + id 'edu.wpi.first.GradleRIO' version '2025.1.1' +} + +version = '1.0.0-alpha.1' + +repositories { + // Use Maven Central for resolving dependencies. + mavenCentral() +} + +dependencies { + implementation wpi.java.deps.wpilib() + implementation wpi.java.vendor.java() + implementation 'com.google.truth:truth:1.4.4' + + nativeDebug wpi.java.deps.wpilibJniDebug(wpi.platforms.desktop) + nativeDebug wpi.java.vendor.jniDebug(wpi.platforms.desktop) + simulationDebug wpi.sim.enableDebug() + + nativeRelease wpi.java.deps.wpilibJniRelease(wpi.platforms.desktop) + nativeRelease wpi.java.vendor.jniRelease(wpi.platforms.desktop) + simulationRelease wpi.sim.enableRelease() + testImplementation(platform('org.junit:junit-bom:5.13.1')) + testImplementation('org.junit.jupiter:junit-jupiter') + testRuntimeOnly('org.junit.platform:junit-platform-launcher') +} + +// the magic line that makes tests work :) +wpi.java.configureTestTasks(test) + +tasks.named('test') { + // Support running both JUnit Vintage and JUnit Jupiter tests + useJUnitPlatform() + systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true' +} + +javadoc { + options.tags = [ + // Converts `@apiNote` paragraph to "Note: " section in the generated javadoc + 'apiNote:a:Api Note:', + // Converts `@implSpec` paragraph to "Implementation Requirements: " section in the generated javadoc + 'implSpec:a:Implementation Requirements:' + ] +} + +// Generates Javadocs for test libraries under /build/docs/testjavadoc +// https://discuss.gradle.org/t/how-configure-gradle-to-generate-javadoc-for-testing-classes-junit/12764/6 +task testJavadoc(type: Javadoc) { + source = sourceSets.test.allJava + classpath = sourceSets.test.compileClasspath + destinationDir = file("${buildDir}/docs/testjavadoc") + println (title == null ? '' : title) +} + +task sourceJar(type: Jar) { + from sourceSets.main.allJava + archiveClassifier = 'sources' +} diff --git a/limelight/src/test/java/com/team2813/lib2813/limelight/truth/Pose2dSubject.java b/testing/src/main/java/com/team2813/lib2813/testing/truth/Pose2dSubject.java similarity index 97% rename from limelight/src/test/java/com/team2813/lib2813/limelight/truth/Pose2dSubject.java rename to testing/src/main/java/com/team2813/lib2813/testing/truth/Pose2dSubject.java index d119af47..f3b33296 100644 --- a/limelight/src/test/java/com/team2813/lib2813/limelight/truth/Pose2dSubject.java +++ b/testing/src/main/java/com/team2813/lib2813/testing/truth/Pose2dSubject.java @@ -1,4 +1,4 @@ -package com.team2813.lib2813.limelight.truth; +package com.team2813.lib2813.testing.truth; import static com.google.common.truth.Fact.simpleFact; import static com.google.common.truth.Truth.assertAbout; diff --git a/limelight/src/test/java/com/team2813/lib2813/limelight/truth/Pose3dSubject.java b/testing/src/main/java/com/team2813/lib2813/testing/truth/Pose3dSubject.java similarity index 97% rename from limelight/src/test/java/com/team2813/lib2813/limelight/truth/Pose3dSubject.java rename to testing/src/main/java/com/team2813/lib2813/testing/truth/Pose3dSubject.java index 160a9899..46990843 100644 --- a/limelight/src/test/java/com/team2813/lib2813/limelight/truth/Pose3dSubject.java +++ b/testing/src/main/java/com/team2813/lib2813/testing/truth/Pose3dSubject.java @@ -1,4 +1,4 @@ -package com.team2813.lib2813.limelight.truth; +package com.team2813.lib2813.testing.truth; import static com.google.common.truth.Fact.simpleFact; import static com.google.common.truth.Truth.assertAbout; diff --git a/limelight/src/test/java/com/team2813/lib2813/limelight/truth/Rotation2dSubject.java b/testing/src/main/java/com/team2813/lib2813/testing/truth/Rotation2dSubject.java similarity index 97% rename from limelight/src/test/java/com/team2813/lib2813/limelight/truth/Rotation2dSubject.java rename to testing/src/main/java/com/team2813/lib2813/testing/truth/Rotation2dSubject.java index 264352ec..d50e4f0a 100644 --- a/limelight/src/test/java/com/team2813/lib2813/limelight/truth/Rotation2dSubject.java +++ b/testing/src/main/java/com/team2813/lib2813/testing/truth/Rotation2dSubject.java @@ -1,4 +1,4 @@ -package com.team2813.lib2813.limelight.truth; +package com.team2813.lib2813.testing.truth; import static com.google.common.truth.Fact.simpleFact; import static com.google.common.truth.Truth.assertAbout; diff --git a/limelight/src/test/java/com/team2813/lib2813/limelight/truth/Rotation3dSubject.java b/testing/src/main/java/com/team2813/lib2813/testing/truth/Rotation3dSubject.java similarity index 98% rename from limelight/src/test/java/com/team2813/lib2813/limelight/truth/Rotation3dSubject.java rename to testing/src/main/java/com/team2813/lib2813/testing/truth/Rotation3dSubject.java index 5503bda7..fe78d230 100644 --- a/limelight/src/test/java/com/team2813/lib2813/limelight/truth/Rotation3dSubject.java +++ b/testing/src/main/java/com/team2813/lib2813/testing/truth/Rotation3dSubject.java @@ -1,4 +1,4 @@ -package com.team2813.lib2813.limelight.truth; +package com.team2813.lib2813.testing.truth; import static com.google.common.truth.Fact.simpleFact; import static com.google.common.truth.Truth.assertAbout; diff --git a/limelight/src/test/java/com/team2813/lib2813/limelight/truth/TolerantComparison.java b/testing/src/main/java/com/team2813/lib2813/testing/truth/TolerantComparison.java similarity index 96% rename from limelight/src/test/java/com/team2813/lib2813/limelight/truth/TolerantComparison.java rename to testing/src/main/java/com/team2813/lib2813/testing/truth/TolerantComparison.java index dd7bed52..cc2c2b38 100644 --- a/limelight/src/test/java/com/team2813/lib2813/limelight/truth/TolerantComparison.java +++ b/testing/src/main/java/com/team2813/lib2813/testing/truth/TolerantComparison.java @@ -1,4 +1,4 @@ -package com.team2813.lib2813.limelight.truth; +package com.team2813.lib2813.testing.truth; import org.jspecify.annotations.Nullable; diff --git a/limelight/src/test/java/com/team2813/lib2813/limelight/truth/Translation2dSubject.java b/testing/src/main/java/com/team2813/lib2813/testing/truth/Translation2dSubject.java similarity index 97% rename from limelight/src/test/java/com/team2813/lib2813/limelight/truth/Translation2dSubject.java rename to testing/src/main/java/com/team2813/lib2813/testing/truth/Translation2dSubject.java index 6f7fdbf5..41a51edd 100644 --- a/limelight/src/test/java/com/team2813/lib2813/limelight/truth/Translation2dSubject.java +++ b/testing/src/main/java/com/team2813/lib2813/testing/truth/Translation2dSubject.java @@ -1,4 +1,4 @@ -package com.team2813.lib2813.limelight.truth; +package com.team2813.lib2813.testing.truth; import static com.google.common.truth.Fact.simpleFact; import static com.google.common.truth.Truth.assertAbout; diff --git a/limelight/src/test/java/com/team2813/lib2813/limelight/truth/Translation3dSubject.java b/testing/src/main/java/com/team2813/lib2813/testing/truth/Translation3dSubject.java similarity index 97% rename from limelight/src/test/java/com/team2813/lib2813/limelight/truth/Translation3dSubject.java rename to testing/src/main/java/com/team2813/lib2813/testing/truth/Translation3dSubject.java index 6659c841..302e1227 100644 --- a/limelight/src/test/java/com/team2813/lib2813/limelight/truth/Translation3dSubject.java +++ b/testing/src/main/java/com/team2813/lib2813/testing/truth/Translation3dSubject.java @@ -1,4 +1,4 @@ -package com.team2813.lib2813.limelight.truth; +package com.team2813.lib2813.testing.truth; import static com.google.common.truth.Fact.simpleFact; import static com.google.common.truth.Truth.assertAbout;