From 4d40e30fd5ccfd46a83d79bb8618beb445b4f09f Mon Sep 17 00:00:00 2001 From: Richard Harrah <1672786+ToppleTheNun@users.noreply.github.com> Date: Mon, 20 May 2024 22:52:11 -0400 Subject: [PATCH] update to develocity plugin (#115) * update to develocity plugin * properly support toolchains --- .github/workflows/gradle.yml | 10 +- README.md | 11 +- settings.gradle.kts | 9 +- .../conventions/MythicDropsJavaExtension.kt | 13 -- .../conventions/MythicDropsJavaPlugin.kt | 12 +- .../gradle/spigot/RunSpigotBuildToolsTask.kt | 184 ++++++++++-------- version.properties | 2 +- versions.properties | 3 +- 8 files changed, 121 insertions(+), 123 deletions(-) delete mode 100644 src/main/kotlin/dev/mythicdrops/gradle/conventions/MythicDropsJavaExtension.kt diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 875793b..17c5e8d 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -49,15 +49,7 @@ jobs: uses: gradle/actions/setup-gradle@aff52e5be96935327d77c5529075184377dc4371 # v3 - name: Perform Build via Gradle - run: ./gradlew build --scan - - - name: Publish to Maven Local via Gradle - run: ./gradlew publishToMavenLocal --scan - - - name: Upload CodeCov Report - uses: codecov/codecov-action@ab904c41d6ece82784817410c45d8b8c02684457 # v3 - with: - files: "**/build/reports/jacoco/**/*.xml" + run: ./gradlew build publishToMavenLocal - name: Publish Plugin and Create GitHub Release via Gradle # Release job, only for pushes to the main development branch diff --git a/README.md b/README.md index 5fb78a9..f853979 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ mythicDropsRelease { The `dev.mythicdrops.gradle.convention.java` plugin will configure the following when applied to any project that also has the `java` plugin applied: -- Configures the project to compile targeting JDK 16 +- Configures the project to compile targeting JDK 17 - Configures the project to pass the `-parameters` javac flag when compiling - Applies the [`jacoco`](https://docs.gradle.org/current/userguide/jacoco_plugin.html) Gradle plugin - Configures the `jacoco` plugin to use JaCoCo 0.8.7 @@ -100,6 +100,15 @@ plugins { } ``` +You can override the JDK version the same way you'd override it in a normal Java project: +```kotlin +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} +``` + ### Kotlin JVM Plugin The `dev.mythicdrops.gradle.conventions.kotlin.jvm` plugin will configure the following when applied to any project that diff --git a/settings.gradle.kts b/settings.gradle.kts index 0d2f0c2..b265405 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,12 +7,13 @@ pluginManagement { plugins { // See https://jmfayard.github.io/refreshVersions id("de.fayard.refreshVersions") version "0.60.5" - id("com.gradle.enterprise") version "3.17.4" + id("com.gradle.develocity") version "3.17.4" } -gradleEnterprise { +develocity { buildScan { - termsOfServiceUrl = "https://gradle.com/terms-of-service" - termsOfServiceAgree = "yes" + publishing.onlyIf { it.buildResult.failures.isNotEmpty() && !System.getenv("CI").isNullOrEmpty() } + termsOfUseUrl = "https://gradle.com/terms-of-service" + termsOfUseAgree = "yes" } } diff --git a/src/main/kotlin/dev/mythicdrops/gradle/conventions/MythicDropsJavaExtension.kt b/src/main/kotlin/dev/mythicdrops/gradle/conventions/MythicDropsJavaExtension.kt deleted file mode 100644 index 5d23179..0000000 --- a/src/main/kotlin/dev/mythicdrops/gradle/conventions/MythicDropsJavaExtension.kt +++ /dev/null @@ -1,13 +0,0 @@ -package dev.mythicdrops.gradle.conventions - -import org.gradle.api.JavaVersion -import org.gradle.api.provider.Property - -/** - * Configuration for selecting which version of Java to compile for. - * - * @property javaVersion Version of Java to compile for (e.g., Java 16/17) - */ -interface MythicDropsJavaExtension { - val javaVersion: Property -} diff --git a/src/main/kotlin/dev/mythicdrops/gradle/conventions/MythicDropsJavaPlugin.kt b/src/main/kotlin/dev/mythicdrops/gradle/conventions/MythicDropsJavaPlugin.kt index f3b4e6c..b55872d 100644 --- a/src/main/kotlin/dev/mythicdrops/gradle/conventions/MythicDropsJavaPlugin.kt +++ b/src/main/kotlin/dev/mythicdrops/gradle/conventions/MythicDropsJavaPlugin.kt @@ -1,33 +1,25 @@ package dev.mythicdrops.gradle.conventions -import org.gradle.api.JavaVersion import org.gradle.api.Project import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.tasks.testing.Test import org.gradle.jvm.toolchain.JavaLanguageVersion import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.withType import org.gradle.testing.jacoco.plugins.JacocoPlugin import org.gradle.testing.jacoco.plugins.JacocoPluginExtension import org.gradle.testing.jacoco.tasks.JacocoReport -val DEFAULT_JAVA_VERSION = JavaVersion.VERSION_17 +const val DEFAULT_JAVA_VERSION = 17 /** * Plugin that configures Java for JDK 17 and enables JaCoCo. */ open class MythicDropsJavaPlugin : DependentPlugin("Java", "java") { override fun configureProject(target: Project) { - val javaExtension = - target.extensions.create("mythicDropsJava").apply { - // default to Java 17 - javaVersion.convention(DEFAULT_JAVA_VERSION) - } - target.configure { toolchain { - languageVersion.set(JavaLanguageVersion.of(javaExtension.javaVersion.get().majorVersion)) + languageVersion.convention(JavaLanguageVersion.of(DEFAULT_JAVA_VERSION)) } } diff --git a/src/main/kotlin/dev/mythicdrops/gradle/spigot/RunSpigotBuildToolsTask.kt b/src/main/kotlin/dev/mythicdrops/gradle/spigot/RunSpigotBuildToolsTask.kt index eb66a47..25b3dd7 100644 --- a/src/main/kotlin/dev/mythicdrops/gradle/spigot/RunSpigotBuildToolsTask.kt +++ b/src/main/kotlin/dev/mythicdrops/gradle/spigot/RunSpigotBuildToolsTask.kt @@ -3,108 +3,126 @@ package dev.mythicdrops.gradle.spigot import org.gradle.api.DefaultTask import org.gradle.api.file.FileSystemOperations import org.gradle.api.file.RegularFileProperty +import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.provider.Property import org.gradle.api.services.ServiceReference import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.Nested import org.gradle.api.tasks.TaskAction +import org.gradle.jvm.toolchain.JavaLauncher +import org.gradle.jvm.toolchain.JavaToolchainService +import org.gradle.kotlin.dsl.getByType import org.gradle.process.ExecOperations import java.io.File import java.nio.file.Paths import javax.inject.Inject -abstract class RunSpigotBuildToolsTask - @Inject - constructor( - private val execOperations: ExecOperations, - private val fileSystemOperations: FileSystemOperations, - ) : DefaultTask() { - @get:ServiceReference(SyncTaskBuildService.NAME) - abstract val syncTask: Property +abstract class RunSpigotBuildToolsTask : DefaultTask() { + @get:ServiceReference(SyncTaskBuildService.NAME) + abstract val syncTask: Property - @get:InputFile - abstract val buildToolsLocation: RegularFileProperty + @get:InputFile + abstract val buildToolsLocation: RegularFileProperty - @get:Input - abstract val includeRemapped: Property + @get:Input + abstract val includeRemapped: Property - @get:Input - abstract val version: Property + @get:Input + abstract val version: Property - init { - description = "Runs Spigot BuildTools.jar for a specific Minecraft version" - group = "spigot" + @get:Nested + abstract val launcher: Property + + @get:Inject + abstract val execOperations: ExecOperations + + @get:Inject + abstract val fileSystemOperations: FileSystemOperations + + @get:Inject + abstract val javaToolchainService: JavaToolchainService + + init { + description = "Runs Spigot BuildTools.jar for a specific Minecraft version" + group = "spigot" + + val toolchain = project.extensions.getByType().toolchain + val defaultLauncher = javaToolchainService.launcherFor(toolchain) + launcher.convention(defaultLauncher) + } + + @TaskAction + fun runSpigotBuildTools() { + val version = version.getOrElse("") + if (version.isBlank()) { + logger.lifecycle("Not running Spigot build tools as the version is blank") + return } - @TaskAction - fun runSpigotBuildTools() { - val version = version.getOrElse("") - if (version.isBlank()) { - logger.lifecycle("Not running Spigot build tools as the version is blank") - return - } - - val mavenLocalDirectory = Paths.get(project.repositories.mavenLocal().url).toFile() - if (!mavenLocalDirectory.exists()) { - logger.lifecycle("Creating Maven Local repository at ${mavenLocalDirectory.absolutePath}") - mavenLocalDirectory.mkdirs() - } - - normalVersion(mavenLocalDirectory, version) - if (includeRemapped.getOrElse(false)) { - remappedVersion(mavenLocalDirectory, version) - } + val mavenLocalDirectory = Paths.get(project.repositories.mavenLocal().url).toFile() + if (!mavenLocalDirectory.exists()) { + logger.lifecycle("Creating Maven Local repository at ${mavenLocalDirectory.absolutePath}") + mavenLocalDirectory.mkdirs() } - private fun normalVersion( - mavenLocalDirectory: File, - version: String, - ) { - val versionJar = - mavenLocalDirectory.resolve( - "org/spigotmc/spigot/$version-R0.1-SNAPSHOT/spigot-$version-R0.1-SNAPSHOT.jar", - ) - if (versionJar.exists()) { - logger.lifecycle("Skipping $version as Spigot JAR is found at ${versionJar.absolutePath}") - return - } - val jar = buildToolsLocation.get().asFile - val versionDir = jar.parentFile.resolve(version) - fileSystemOperations.copy { - from(jar) - into(versionDir) - } - execOperations.javaexec { - args(listOf("--rev", version)) - workingDir = versionDir.absoluteFile - jvmArgs = listOf("-Xmx1024M") - classpath(buildToolsLocation) - } + normalVersion(mavenLocalDirectory, version) + if (includeRemapped.getOrElse(false)) { + remappedVersion(mavenLocalDirectory, version) } + } - private fun remappedVersion( - mavenLocalDirectory: File, - version: String, - ) { - val versionJar = - mavenLocalDirectory.resolve( - "org/spigotmc/spigot/$version-R0.1-SNAPSHOT/spigot-$version-R0.1-SNAPSHOT-remapped-mojang.jar", - ) - if (versionJar.exists()) { - logger.lifecycle("Skipping $version as Spigot remapped JAR is found at ${versionJar.absolutePath}") - return - } - val jar = buildToolsLocation.get().asFile - val versionDir = jar.parentFile.resolve(version) - fileSystemOperations.copy { - from(jar) - into(versionDir) - } - execOperations.javaexec { - args(listOf("--rev", version, "--remapped")) - workingDir = versionDir.absoluteFile - jvmArgs = listOf("-Xmx1024M") - classpath(buildToolsLocation) - } + private fun normalVersion( + mavenLocalDirectory: File, + version: String, + ) { + val versionJar = + mavenLocalDirectory.resolve( + "org/spigotmc/spigot/$version-R0.1-SNAPSHOT/spigot-$version-R0.1-SNAPSHOT.jar", + ) + if (versionJar.exists()) { + logger.lifecycle("Skipping $version as Spigot JAR is found at ${versionJar.absolutePath}") + return + } + val jar = buildToolsLocation.get().asFile + val versionDir = jar.parentFile.resolve(version) + fileSystemOperations.copy { + from(jar) + into(versionDir) + } + execOperations.javaexec { + args(listOf("--rev", version)) + workingDir = versionDir.absoluteFile + jvmArgs = listOf("-Xmx1024M") + classpath(buildToolsLocation) + executable(launcher.get().executablePath) + } + } + + private fun remappedVersion( + mavenLocalDirectory: File, + version: String, + ) { + val versionJar = + mavenLocalDirectory.resolve( + "org/spigotmc/spigot/$version-R0.1-SNAPSHOT/spigot-$version-R0.1-SNAPSHOT-remapped-mojang.jar", + ) + if (versionJar.exists()) { + logger.lifecycle("Skipping $version as Spigot remapped JAR is found at ${versionJar.absolutePath}") + return + } + val jar = buildToolsLocation.get().asFile + val versionDir = jar.parentFile.resolve(version) + fileSystemOperations.copy { + from(jar) + into(versionDir) + } + execOperations.javaexec { + args(listOf("--rev", version, "--remapped")) + workingDir = versionDir.absoluteFile + jvmArgs = listOf("-Xmx1024M") + classpath(buildToolsLocation) + executable(launcher.get().executablePath) } } +} diff --git a/version.properties b/version.properties index fa33d8a..80f95e5 100644 --- a/version.properties +++ b/version.properties @@ -1 +1 @@ -version=7.2.* +version=8.0.* diff --git a/versions.properties b/versions.properties index 5f8aa3b..302c49d 100644 --- a/versions.properties +++ b/versions.properties @@ -13,8 +13,7 @@ plugin.io.gitlab.arturbosch.detekt=1.23.6 plugin.org.jetbrains.dokka=1.9.20 -plugin.org.jlleitschuh.gradle.ktlint=12.1.0 -## # available=12.1.1 +plugin.org.jlleitschuh.gradle.ktlint=12.1.1 plugin.org.shipkit.shipkit-auto-version=2.0.7