From 4a9c98aa1b93eeb1d25f37ee573d77402de4a86a Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 17 Nov 2024 13:45:25 +0100 Subject: [PATCH] Address Gradle deprecation warnings --- build-logic/src/main/kotlin/extensions.kt | 33 ++++++++--------------- build.gradle.kts | 4 +-- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/build-logic/src/main/kotlin/extensions.kt b/build-logic/src/main/kotlin/extensions.kt index 0b0b7dee..71acb974 100644 --- a/build-logic/src/main/kotlin/extensions.kt +++ b/build-logic/src/main/kotlin/extensions.kt @@ -1,33 +1,23 @@ -import org.gradle.api.JavaVersion import org.gradle.api.Project import org.gradle.api.plugins.JavaPluginExtension -import java.io.ByteArrayOutputStream +import org.gradle.jvm.toolchain.JavaLanguageVersion fun Project.latestCommitHash(): String { - val byteOut = ByteArrayOutputStream() - exec { - commandLine = listOf("git", "rev-parse", "--short", "HEAD") - standardOutput = byteOut - } - return byteOut.toString(Charsets.UTF_8.name()).trim() + return runGitCommand(listOf("rev-parse", "--short", "HEAD")) } fun Project.latestCommitMessage(): String { - val byteOut = ByteArrayOutputStream() - exec { - commandLine = listOf("git", "log", "-1", "--pretty=%B") - standardOutput = byteOut - } - return byteOut.toString(Charsets.UTF_8.name()).trim() + return runGitCommand(listOf("log", "-1", "--pretty=%B")) } fun Project.branchName(): String { - val byteOut = ByteArrayOutputStream() - exec { - commandLine = listOf("git", "rev-parse", "--abbrev-ref", "HEAD") - standardOutput = byteOut - } - return byteOut.toString(Charsets.UTF_8.name()).trim() + return runGitCommand(listOf("rev-parse", "--abbrev-ref", "HEAD")) +} + +fun Project.runGitCommand(args: List): String { + return providers.exec { + commandLine = listOf("git") + args + }.standardOutput.asBytes.get().toString(Charsets.UTF_8).trim() } fun Project.parseMinecraftSnapshotVersion(version: String): String? { @@ -40,6 +30,5 @@ fun Project.parseMinecraftSnapshotVersion(version: String): String? { } fun JavaPluginExtension.javaTarget(version: Int) { - sourceCompatibility = JavaVersion.toVersion(version) - targetCompatibility = JavaVersion.toVersion(version) + toolchain.languageVersion.set(JavaLanguageVersion.of(version)) } diff --git a/build.gradle.kts b/build.gradle.kts index f5f6243f..905f5907 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,10 +16,10 @@ val main = setOf( projects.viabackwardsVelocity, projects.viabackwardsSponge, projects.viabackwardsFabric -).map { it.dependencyProject } +).map { it.path } subprojects { - when (this) { + when (path) { in main -> plugins.apply("vb.shadow-conventions") else -> plugins.apply("vb.base-conventions") }