From b6ec2c64b201c7ac9944308f40691777172bc722 Mon Sep 17 00:00:00 2001 From: Zach Harel Date: Tue, 18 Aug 2026 15:41:30 -0400 Subject: [PATCH] use build-logic for gradle config Signed-off-by: Zach Harel --- build-logic/build.gradle.kts | 22 +++ build-logic/settings.gradle.kts | 16 +++ ...v.nextftc.suite.android-library.gradle.kts | 33 +++++ .../dev.nextftc.suite.kotlin-jvm.gradle.kts | 20 +++ .../dev.nextftc.suite.publishing.gradle.kts | 127 ++++++++++++++++++ ...c.suite.publishing.multi-module.gradle.kts | 37 +++++ .../kotlin/dev/nextftc/suite/build/Ktlint.kt | 9 ++ .../suite/build/NextFtcPublishingExtension.kt | 17 +++ build.gradle.kts | 71 +--------- control/build.gradle.kts | 18 +-- gradle/libs.versions.toml | 5 +- hardware/build.gradle.kts | 31 +---- linalg/build.gradle.kts | 14 +- robot/build.gradle.kts | 34 +---- settings.gradle.kts | 2 + units/build.gradle.kts | 14 +- 16 files changed, 292 insertions(+), 178 deletions(-) create mode 100644 build-logic/build.gradle.kts create mode 100644 build-logic/settings.gradle.kts create mode 100644 build-logic/src/main/kotlin/dev.nextftc.suite.android-library.gradle.kts create mode 100644 build-logic/src/main/kotlin/dev.nextftc.suite.kotlin-jvm.gradle.kts create mode 100644 build-logic/src/main/kotlin/dev.nextftc.suite.publishing.gradle.kts create mode 100644 build-logic/src/main/kotlin/dev.nextftc.suite.publishing.multi-module.gradle.kts create mode 100644 build-logic/src/main/kotlin/dev/nextftc/suite/build/Ktlint.kt create mode 100644 build-logic/src/main/kotlin/dev/nextftc/suite/build/NextFtcPublishingExtension.kt diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts new file mode 100644 index 0000000..a31c2d6 --- /dev/null +++ b/build-logic/build.gradle.kts @@ -0,0 +1,22 @@ +plugins { + `kotlin-dsl` +} + +group = "dev.nextftc.suite.build" + +repositories { + google() + mavenCentral() +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.3.0") + implementation("org.jetbrains.dokka:dokka-gradle-plugin:2.2.0") + implementation("io.deepmedia.tools.deployer:deployer:0.18.0") + implementation("com.diffplug.spotless:spotless-plugin-gradle:8.1.0") + implementation("com.android.tools.build:gradle:8.7.3") +} + +kotlin { + jvmToolchain(17) +} diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts new file mode 100644 index 0000000..51c761f --- /dev/null +++ b/build-logic/settings.gradle.kts @@ -0,0 +1,16 @@ +pluginManagement { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} + +dependencyResolutionManagement { + repositories { + google() + mavenCentral() + } +} + +rootProject.name = "build-logic" diff --git a/build-logic/src/main/kotlin/dev.nextftc.suite.android-library.gradle.kts b/build-logic/src/main/kotlin/dev.nextftc.suite.android-library.gradle.kts new file mode 100644 index 0000000..3481e26 --- /dev/null +++ b/build-logic/src/main/kotlin/dev.nextftc.suite.android-library.gradle.kts @@ -0,0 +1,33 @@ +plugins { + id("com.android.library") + id("org.jetbrains.kotlin.android") +} + +android { + compileSdk = 30 + + defaultConfig { + minSdk = 24 + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + + testOptions { + targetSdk = 28 + } +} + +kotlin { + jvmToolchain(8) + compilerOptions { + freeCompilerArgs.add("-Xconsistent-data-class-copy-visibility") + } +} + +tasks.withType().configureEach { + javaLauncher.set(javaToolchains.launcherFor { languageVersion.set(JavaLanguageVersion.of(11)) }) + useJUnitPlatform() +} diff --git a/build-logic/src/main/kotlin/dev.nextftc.suite.kotlin-jvm.gradle.kts b/build-logic/src/main/kotlin/dev.nextftc.suite.kotlin-jvm.gradle.kts new file mode 100644 index 0000000..18f5d9c --- /dev/null +++ b/build-logic/src/main/kotlin/dev.nextftc.suite.kotlin-jvm.gradle.kts @@ -0,0 +1,20 @@ +plugins { + id("org.jetbrains.kotlin.jvm") +} + +kotlin { + jvmToolchain(8) + compilerOptions { + freeCompilerArgs.add("-Xconsistent-data-class-copy-visibility") + } +} + +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(8)) + } +} + +tasks.withType().configureEach { + useJUnitPlatform() +} diff --git a/build-logic/src/main/kotlin/dev.nextftc.suite.publishing.gradle.kts b/build-logic/src/main/kotlin/dev.nextftc.suite.publishing.gradle.kts new file mode 100644 index 0000000..8ae680b --- /dev/null +++ b/build-logic/src/main/kotlin/dev.nextftc.suite.publishing.gradle.kts @@ -0,0 +1,127 @@ +import com.android.build.api.dsl.LibraryExtension +import com.diffplug.gradle.spotless.SpotlessExtension +import dev.nextftc.suite.build.NextFtcPublishingExtension +import dev.nextftc.suite.build.nextFtcKtlintEditorConfig +import org.gradle.jvm.tasks.Jar +import org.jetbrains.dokka.gradle.DokkaExtension +import org.jetbrains.dokka.gradle.engine.plugins.DokkaHtmlPluginParameters + +plugins { + id("org.jetbrains.dokka") + id("io.deepmedia.tools.deployer") + id("com.diffplug.spotless") +} + +val extension = extensions.create("nextFTCPublishing") + +dependencies { + add("dokkaPlugin", "org.jetbrains.dokka:mathjax-plugin") +} + +configure { + kotlin { + target("src/*/kotlin/**/*.kt") + ktlint().editorConfigOverride(nextFtcKtlintEditorConfig) + } +} + +configure { + pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { + dokkaSourceSets.named("main") { + sourceRoots.from(file("src/main/kotlin")) + + sourceLink { + localDirectory.set(file("src/main/kotlin")) + remoteUrl("https://github.com/NextFTC/NextFTCSuite/blob/main/${project.name}/src/main/kotlin") + remoteLineSuffix.set("#L") + } + } + } + + moduleName.set(extension.displayName) + + pluginsConfiguration.named("html") { + footerMessage.set("Copyright © 2026 NextFTC - Licensed under the BSD-3-Clause license.") + customAssets.from(extension.logoPath) + } +} + +val dokkaExtension = extensions.getByType() + +val dokkaJar by tasks.registering(Jar::class) { + dependsOn(tasks.named("dokkaGenerate")) + from(dokkaExtension.basePublicationsDirectory.dir("html")) + archiveClassifier.set("html-docs") +} + +deployer { + projectInfo { + url = "https://nextftc.dev/" + scm { + fromGithub("NextFTC", "NextFTCSuite") + } + license("BSD 3-Clause License", "https://opensource.org/license/bsd-3-clause") + developer("Zach Harel", "zach@zharel.me", url = "https://github.com/zachwaffle4") + developer( + "Davis Luxenberg", + "davis.luxenberg@outlook.com", + url = "https://github.com/BeepBot99", + ) + developer("Rowan McAlpin", "rowan@nextftc.dev", url = "https://rowanmcalpin.com") + + name.set(extension.displayName) + groupId.set(extension.group) + } + + signing { + key.set(secret("MVN_GPG_KEY")) + password.set(secret("MVN_GPG_PASSWORD")) + } + + content { + pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { + kotlinComponents { + kotlinSources() + docs(dokkaJar) + } + } + + pluginManager.withPlugin("com.android.library") { + pluginManager.withPlugin("org.jetbrains.kotlin.android") { + configure { + publishing { + singleVariant("release") { + withSourcesJar() + } + } + } + + androidComponents("release") { + docs(dokkaJar) + } + } + } + } + + release { + version.set(extension.version) + } + + localSpec() + + nexusSpec("snapshot") { + repositoryUrl.set("https://central.sonatype.com/repository/maven-snapshots/") + auth { + user.set(secret("SONATYPE_USERNAME")) + password.set(secret("SONATYPE_PASSWORD")) + } + } + + centralPortalSpec { + auth { + user.set(secret("SONATYPE_USERNAME")) + password.set(secret("SONATYPE_PASSWORD")) + } + allowMavenCentralSync.set(extension.automaticMavenCentralSync) + } +} diff --git a/build-logic/src/main/kotlin/dev.nextftc.suite.publishing.multi-module.gradle.kts b/build-logic/src/main/kotlin/dev.nextftc.suite.publishing.multi-module.gradle.kts new file mode 100644 index 0000000..6cf20da --- /dev/null +++ b/build-logic/src/main/kotlin/dev.nextftc.suite.publishing.multi-module.gradle.kts @@ -0,0 +1,37 @@ +import com.diffplug.gradle.spotless.SpotlessExtension +import dev.nextftc.suite.build.nextFtcKtlintEditorConfig + +allprojects { + apply(plugin = "com.diffplug.spotless") + + version = property("version") as String + group = "dev.nextftc.v2" + + extensions.configure { + kotlinGradle { + ktlint().editorConfigOverride(nextFtcKtlintEditorConfig) + } + } +} + +subprojects { + pluginManager.apply("dev.nextftc.suite.publishing") +} + +tasks.register("deployCentralPortal") { + group = "publishing" + description = "Publishes all subprojects to Maven Central." + dependsOn(subprojects.map { "${it.path}:deployCentralPortal" }) +} + +tasks.register("deployLocal") { + group = "publishing" + description = "Publishes all subprojects to Maven Local." + dependsOn(subprojects.map { "${it.path}:deployLocal" }) +} + +tasks.register("deployNexusSnapshot") { + group = "publishing" + description = "Publishes all subprojects to Maven Central Snapshots." + dependsOn(subprojects.map { "${it.path}:deployNexusSnapshot" }) +} diff --git a/build-logic/src/main/kotlin/dev/nextftc/suite/build/Ktlint.kt b/build-logic/src/main/kotlin/dev/nextftc/suite/build/Ktlint.kt new file mode 100644 index 0000000..9193804 --- /dev/null +++ b/build-logic/src/main/kotlin/dev/nextftc/suite/build/Ktlint.kt @@ -0,0 +1,9 @@ +package dev.nextftc.suite.build + +val nextFtcKtlintEditorConfig = mapOf( + "ktlint_code_style" to "intellij_idea", + "indent_size" to "2", + "continuation_indent_size" to "2", + "ktlint_standard_no-wildcard-imports" to "disabled", + "max_line_length" to "108", +) diff --git a/build-logic/src/main/kotlin/dev/nextftc/suite/build/NextFtcPublishingExtension.kt b/build-logic/src/main/kotlin/dev/nextftc/suite/build/NextFtcPublishingExtension.kt new file mode 100644 index 0000000..521e68f --- /dev/null +++ b/build-logic/src/main/kotlin/dev/nextftc/suite/build/NextFtcPublishingExtension.kt @@ -0,0 +1,17 @@ +package dev.nextftc.suite.build + +import org.gradle.api.Project +import org.gradle.api.model.ObjectFactory +import org.gradle.kotlin.dsl.property +import javax.inject.Inject + +open class NextFtcPublishingExtension @Inject constructor(objects: ObjectFactory, project: Project) { + val displayName = objects.property() + val version = objects.property().convention(project.provider { project.version.toString() }) + val group = objects.property().convention(project.provider { project.group.toString() }) + val automaticMavenCentralSync = objects.property() + .convention( + project.providers.gradleProperty("dev.nextftc.publishing.automaticMavenCentralSync").map(String::toBoolean), + ) + val logoPath = objects.property().convention("assets/logo-icon.svg") +} diff --git a/build.gradle.kts b/build.gradle.kts index fee532d..16cb08b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,80 +1,11 @@ -import com.diffplug.gradle.spotless.SpotlessExtension -import io.deepmedia.tools.deployer.DeployerExtension - plugins { alias(libs.plugins.kotlin) apply false alias(libs.plugins.kotlin.android) apply false alias(libs.plugins.android.library) apply false - alias(libs.plugins.nextftc.publishing) - alias(libs.plugins.spotless) + id("dev.nextftc.suite.publishing.multi-module") alias(libs.plugins.dokka) } -allprojects { - apply(plugin = "com.diffplug.spotless") - - version = property("version") as String - group = "dev.nextftc.v2" - - extensions.configure { - kotlinGradle { - ktlint().editorConfigOverride( - mapOf( - "ktlint_code_style" to "intellij_idea", - "indent_size" to "2", - "continuation_indent_size" to "2", - "ktlint_standard_no-wildcard-imports" to "disabled", - "max_line_length" to "108", - ), - ) - } - } -} - -subprojects { - extensions.configure { - projectInfo { - url = "https://nextftc.dev/" - scm { - fromGithub("NextFTC", "NextFTCSuite") - } - license("BSD 3-Clause License", "https://opensource.org/license/bsd-3-clause") - developer("Zach Harel", "zach@zharel.me", url = "https://github.com/zachwaffle4") - developer( - "Davis Luxenberg", - "davis.luxenberg@outlook.com", - url = "https://github.com/BeepBot99", - ) - developer("Rowan McAlpin", "rowan@nextftc.dev", url = "https://rowanmcalpin.com") - } - } - - dokka { - pluginsConfiguration.html { - footerMessage.set("Copyright © 2026 NextFTC - Licensed under the BSD-3-Clause license.") - } - } - - dependencies { - dokkaPlugin("org.jetbrains.dokka:mathjax-plugin") - } - - extensions.configure { - kotlin { - target("src/*/kotlin/**/*.kt") - ktlint().editorConfigOverride( - mapOf( - "ktlint_code_style" to "intellij_idea", - "indent_size" to "2", - "continuation_indent_size" to "2", - "ktlint_standard_no-wildcard-imports" to "disabled", - "max_line_length" to "108", - ), - ) - } - } -} - dependencies { dokka(project(":units")) dokka(project(":linalg")) diff --git a/control/build.gradle.kts b/control/build.gradle.kts index 7aaecb7..4fa0535 100644 --- a/control/build.gradle.kts +++ b/control/build.gradle.kts @@ -1,6 +1,5 @@ plugins { - alias(libs.plugins.kotlin) - alias(libs.plugins.spotless) + id("dev.nextftc.suite.kotlin-jvm") } description = "A WPIMath inspired library for controls and other math classes and functions." @@ -22,18 +21,3 @@ dokka { includes.from("Module.md") } } - -kotlin { - jvmToolchain(8) - compilerOptions { - freeCompilerArgs.addAll("-Xconsistent-data-class-copy-visibility") - } -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) - } -} - -tasks.withType().configureEach { useJUnitPlatform() } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f87c6df..a222724 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,7 +5,6 @@ ftc = "11.1.0" kotlin = "2.3.0" kotest = "5.9.1" sloth = "0.2.4" -spotless = "8.1.0" ejml = "0.41" ivy = "1.0.1" @@ -33,6 +32,4 @@ ftc = ["ftc-robot-core", "ftc-hardware", "ftc-common"] kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } android-library = { id = "com.android.library", version.ref = "android" } -dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } -nextftc-publishing = { id = "dev.nextftc.publishing.multi-module", version = "1.0.1" } -spotless = { id = "com.diffplug.spotless", version.ref = "spotless" } \ No newline at end of file +dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } \ No newline at end of file diff --git a/hardware/build.gradle.kts b/hardware/build.gradle.kts index 07818dd..25c8e86 100644 --- a/hardware/build.gradle.kts +++ b/hardware/build.gradle.kts @@ -7,41 +7,17 @@ */ plugins { - alias(libs.plugins.android.library) - alias(libs.plugins.kotlin.android) - alias(libs.plugins.spotless) + id("dev.nextftc.suite.android-library") } android { namespace = "dev.nextftc.v2.hardware" - compileSdk = 30 - - defaultConfig { - minSdk = 24 - } - - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } - - publishing { - singleVariant("release") - } testOptions { - targetSdk = 28 unitTests.isReturnDefaultValues = true } } -kotlin { - jvmToolchain(8) - compilerOptions { - freeCompilerArgs.addAll("-Xconsistent-data-class-copy-visibility") - } -} - dependencies { api(project(":control")) api(libs.functional.interfaces) @@ -78,8 +54,3 @@ dokka { } } } - -tasks.withType().configureEach { - javaLauncher.set(javaToolchains.launcherFor { languageVersion.set(JavaLanguageVersion.of(11)) }) - useJUnitPlatform() -} diff --git a/linalg/build.gradle.kts b/linalg/build.gradle.kts index 08a284a..4755c61 100644 --- a/linalg/build.gradle.kts +++ b/linalg/build.gradle.kts @@ -1,6 +1,5 @@ plugins { - alias(libs.plugins.kotlin) - alias(libs.plugins.spotless) + id("dev.nextftc.suite.kotlin-jvm") } description = "A custom linear algebra library for NextControl." @@ -23,16 +22,7 @@ dokka { } kotlin { - jvmToolchain(8) compilerOptions { - freeCompilerArgs.addAll("-jvm-default=no-compatibility", "-Xconsistent-data-class-copy-visibility") + freeCompilerArgs.add("-jvm-default=no-compatibility") } } - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) - } -} - -tasks.withType().configureEach { useJUnitPlatform() } diff --git a/robot/build.gradle.kts b/robot/build.gradle.kts index 6cc79d8..d3e7122 100644 --- a/robot/build.gradle.kts +++ b/robot/build.gradle.kts @@ -7,38 +7,11 @@ */ plugins { - alias(libs.plugins.kotlin.android) - alias(libs.plugins.android.library) - alias(libs.plugins.spotless) + id("dev.nextftc.suite.android-library") } android { namespace = "dev.nextftc.v2.robot" - compileSdk = 30 - - defaultConfig { - minSdk = 24 - } - - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } - - publishing { - singleVariant("release") - } - - testOptions { - targetSdk = 28 - } -} - -kotlin { - jvmToolchain(8) - compilerOptions { - freeCompilerArgs.addAll("-Xconsistent-data-class-copy-visibility") - } } dependencies { @@ -65,8 +38,3 @@ dokka { includes.from("Module.md") } } - -tasks.withType().configureEach { - javaLauncher.set(javaToolchains.launcherFor { languageVersion.set(JavaLanguageVersion.of(11)) }) - useJUnitPlatform() -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 5fe35a2..5174cdf 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,4 +1,6 @@ pluginManagement { + includeBuild("build-logic") + repositories { google() mavenCentral() diff --git a/units/build.gradle.kts b/units/build.gradle.kts index eb6aaa3..a252e86 100644 --- a/units/build.gradle.kts +++ b/units/build.gradle.kts @@ -1,6 +1,5 @@ plugins { - alias(libs.plugins.kotlin) - alias(libs.plugins.spotless) + id("dev.nextftc.suite.kotlin-jvm") } description = "A custom units library for NextControl." @@ -19,16 +18,7 @@ dokka { } kotlin { - jvmToolchain(8) compilerOptions { - freeCompilerArgs.addAll("-jvm-default=no-compatibility", "-Xconsistent-data-class-copy-visibility") + freeCompilerArgs.add("-jvm-default=no-compatibility") } } - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) - } -} - -tasks.withType().configureEach { useJUnitPlatform() }