Skip to content

Commit

Permalink
Update Gradle to 8.4 (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla authored Nov 20, 2023
1 parent 7d2ae18 commit 3be0f6c
Show file tree
Hide file tree
Showing 29 changed files with 132 additions and 129 deletions.
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {

dependencies {
implementation(libs.gradle.licenser)
implementation(libs.gradle.ktlint)
implementation(libs.gradle.spotless)
implementation(libs.gradle.shadow)
implementation(libs.gradle.kotlin.dsl)
implementation(libs.gradle.plugin.kotlin.withVersion(embeddedKotlinVersion))
Expand Down
2 changes: 0 additions & 2 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
rootProject.name = "buildSrc"

enableFeaturePreview("VERSION_CATALOGS")

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
Expand Down
35 changes: 23 additions & 12 deletions buildSrc/src/main/kotlin/config-kotlin.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
idea
id("org.gradle.kotlin.kotlin-dsl")
id("org.cadixdev.licenser")
id("org.jlleitschuh.gradle.ktlint")
id("net.kyori.indra.licenser.spotless")
}

java {
Expand Down Expand Up @@ -74,21 +73,33 @@ tasks.jar {
}
}

ktlint {
enableExperimentalRules.set(true)

disabledRules.add("no-wildcard-imports")
}

tasks.register("format") {
group = "formatting"
description = "Formats source code according to project style"
dependsOn(tasks.licenseFormat, tasks.ktlintFormat)
dependsOn(tasks.spotlessApply)
}

indraSpotlessLicenser {
licenseHeaderFile(rootProject.file("license/copyright.txt"))
newLine(true)
}

license {
header.set(resources.text.fromFile(rootProject.file("license/copyright.txt")))
include("**/*.kt")
spotless {
val overrides = mapOf(
"ktlint_standard_no-wildcard-imports" to "disabled",
"ktlint_standard_filename" to "disabled",
"ktlint_standard_trailing-comma-on-call-site" to "disabled",
"ktlint_standard_trailing-comma-on-declaration-site" to "disabled",
)

val ktlintVer = "0.50.0"

kotlin {
ktlint(ktlintVer).editorConfigOverride(overrides)
}
kotlinGradle {
ktlint(ktlintVer).editorConfigOverride(overrides)
}
}

idea {
Expand Down
16 changes: 10 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ hypo = "1.2.4"
asm-core = { module = "org.ow2.asm:asm", version.ref = "asm" }
asm-tree = { module = "org.ow2.asm:asm-tree", version.ref = "asm" }

httpclient = "org.apache.httpcomponents:httpclient:4.5.13"
httpclient = "org.apache.httpcomponents:httpclient:4.5.14"
kotson = "com.github.salomonbrys.kotson:kotson:2.5.0"
gson = "com.google.code.gson:gson:2.10.1"

cadix-lorenz-core = { module = "org.cadixdev:lorenz", version.ref = "lorenz" }
cadix-lorenz-asm = { module = "org.cadixdev:lorenz-asm", version.ref = "lorenz" }
Expand All @@ -28,15 +29,18 @@ slf4j-jdk14 = "org.slf4j:slf4j-jdk14:1.7.32"
lorenzTiny = "net.fabricmc:lorenz-tiny:3.0.0"
jbsdiff = "io.sigpipe:jbsdiff:1.0"

diffpatch = "net.minecraftforge:DiffPatch:2.0.7"

# Gradle
gradle-licenser = "org.cadixdev.licenser:org.cadixdev.licenser.gradle.plugin:0.6.1"
gradle-shadow = "com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:7.1.2"
gradle-ktlint = "org.jlleitschuh.gradle.ktlint:org.jlleitschuh.gradle.ktlint.gradle.plugin:10.2.1"
gradle-kotlin-dsl = "org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:2.4.1"
gradle-licenser = "net.kyori:indra-licenser-spotless:3.1.3"
gradle-spotless = "com.diffplug.spotless:spotless-plugin-gradle:6.22.0"
gradle-shadow = "com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:8.1.1"
gradle-kotlin-dsl = "org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:4.1.2"
gradle-plugin-kotlin = { module = "org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin" }
gradle-plugin-publish = "com.gradle.publish:plugin-publish-plugin:1.1.0"
gradle-plugin-publish = "com.gradle.publish:plugin-publish-plugin:1.2.1"

[bundles]
asm = ["asm-core", "asm-tree"]
cadix = ["cadix-lorenz-core", "cadix-lorenz-asm", "cadix-lorenz-proguard", "cadix-atlas", "cadix-at", "cadix-mercury"]
hypo = ["hypo-model", "hypo-core", "hypo-hydrate", "hypo-asm-core", "hypo-asm-hydrate", "hypo-mappings"]
kotson = ["kotson", "gson"]
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
29 changes: 17 additions & 12 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,26 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
2 changes: 1 addition & 1 deletion paperweight-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
dependencies {
shade(projects.paperweightLib)

implementation(libs.kotson)
implementation(libs.bundles.kotson)
}

gradlePlugin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ open class CraftBukkitExtension(objects: ObjectFactory, workDir: DirectoryProper
val specialSourceJar: RegularFileProperty = objects.fileFrom(buildDataBinDir, "SpecialSource.jar")
val specialSource2Jar: RegularFileProperty = objects.fileFrom(buildDataBinDir, "SpecialSource-2.jar")

private fun ObjectFactory.bukkitFileFrom(base: DirectoryProperty, extension: String): RegularFileProperty =
fileProperty().convention(
base.flatMap { dir ->
val file = dir.path.useDirectoryEntries { it.filter { f -> f.name.endsWith(extension) }.singleOrNull() }
if (file != null) {
mappingsDir.file(file.name)
} else {
fileProperty()
}
private fun ObjectFactory.bukkitFileFrom(base: DirectoryProperty, extension: String): RegularFileProperty = fileProperty().convention(
base.flatMap { dir ->
val file = dir.path.useDirectoryEntries { it.filter { f -> f.name.endsWith(extension) }.singleOrNull() }
if (file != null) {
mappingsDir.file(file.name)
} else {
fileProperty()
}
)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ open class PaperweightCoreExtension(project: Project, objects: ObjectFactory, la
val serverProject: Property<Project> = objects.property()

val mainClass: Property<String> = objects.property<String>().convention("org.bukkit.craftbukkit.Main")
val bundlerJarName: Property<String> = objects.property<String>().convention(project.name.toLowerCase(Locale.ENGLISH))
val bundlerJarName: Property<String> = objects.property<String>().convention(project.name.lowercase(Locale.ENGLISH))

val mcDevSourceDir: DirectoryProperty = objects.directoryProperty().convention(serverProject.map { it.layout.cacheDir(MC_DEV_SOURCES_DIR) })

Expand Down
4 changes: 2 additions & 2 deletions paperweight-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

dependencies {
implementation(libs.httpclient)
implementation(libs.kotson)
implementation(libs.bundles.kotson)

// ASM for inspection
implementation(libs.bundles.asm)
Expand All @@ -17,7 +17,7 @@ dependencies {

implementation(libs.jbsdiff)

implementation("net.minecraftforge:DiffPatch:2.0.7:all") {
implementation(variantOf(libs.diffpatch) { classifier("all") }) {
isTransitive = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ abstract class DownloadService : BuildService<BuildServiceParameters.None>, Auto
if (hash == null) {
return
}
val dlHash = target.hashFile(hash.algorithm).asHexString().toLowerCase(Locale.ENGLISH)
val dlHash = target.hashFile(hash.algorithm).asHexString().lowercase(Locale.ENGLISH)
if (dlHash == hash.valueLower) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class BundlerJarTasks(
private fun Project.createBundlerJarTask(
classifier: String = "",
): Pair<TaskProvider<CreateBundlerJar>, TaskProvider<CreatePaperclipJar>> {
val bundlerTaskName = "create${classifier.capitalize()}BundlerJar"
val paperclipTaskName = "create${classifier.capitalize()}PaperclipJar"
val bundlerTaskName = "create${classifier.capitalized()}BundlerJar"
val paperclipTaskName = "create${classifier.capitalized()}PaperclipJar"

val bundlerJarTask = tasks.register<CreateBundlerJar>(bundlerTaskName) {
group = "paperweight"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ class DevBundleTasks(
bundlerJarName: String,
mainClassName: Property<String>,
minecraftVer: Provider<String>,
decompileJar: Provider<Path?>,
serverLibrariesTxt: Provider<Path?>,
serverLibrariesListFile: Provider<Path?>,
vanillaBundlerJarFile: Provider<Path?>,
accessTransformFile: Provider<Path?>,
decompileJar: Provider<Path>,
serverLibrariesTxt: Provider<Path>,
serverLibrariesListFile: Provider<Path>,
vanillaBundlerJarFile: Provider<Path>,
accessTransformFile: Provider<Path>,
versionJsonFile: Provider<RegularFile>,
devBundleConfiguration: GenerateDevBundle.() -> Unit
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,11 @@ abstract class GenerateDevBundle : DefaultTask() {
}
}

private fun excluded(relocation: Relocation, potential: String): Boolean =
relocation.excludes.map {
it.replace('.', '/')
}.any { exclude ->
SelectorUtils.matchPath(exclude, potential, true)
}
private fun excluded(relocation: Relocation, potential: String): Boolean = relocation.excludes.map {
it.replace('.', '/')
}.any { exclude ->
SelectorUtils.matchPath(exclude, potential, true)
}

private fun diffFiles(fileName: String, original: Path, patched: Path): String {
val dir = createTempDirectory("diff")
Expand Down Expand Up @@ -372,7 +371,7 @@ abstract class GenerateDevBundle : DefaultTask() {
dependency.versionConstraint.preferredVersion,
dependency.version
).first { it.isNotBlank() }
new += ModuleId(dependency.group, dependency.name, version)
new += ModuleId(dependency.group ?: error("Missing group for $dependency"), dependency.name, version)
}

for (vanillaLib in vanillaServerLibraries) {
Expand Down Expand Up @@ -447,7 +446,7 @@ abstract class GenerateDevBundle : DefaultTask() {
const val currentDataVersion = 3

fun createCoordinatesFor(project: Project): String =
sequenceOf(project.group, project.name.toLowerCase(Locale.ENGLISH), "userdev-" + project.version).joinToString(":")
sequenceOf(project.group, project.name.lowercase(Locale.ENGLISH), "userdev-" + project.version).joinToString(":")
}

private fun checkEnvironment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import org.gradle.api.model.ObjectFactory
fun ObjectFactory.dirWithDefault(layout: ProjectLayout, path: String): DirectoryProperty =
directoryProperty().convention(layout.projectDirectory.dir(path))

fun ObjectFactory.dirFrom(base: DirectoryProperty, name: String): DirectoryProperty =
directoryProperty().convention(base.dir(name))
fun ObjectFactory.dirFrom(base: DirectoryProperty, name: String): DirectoryProperty = directoryProperty().convention(base.dir(name))

fun ObjectFactory.fileFrom(base: DirectoryProperty, name: String): RegularFileProperty =
fileProperty().convention(base.file(name))
fun ObjectFactory.fileFrom(base: DirectoryProperty, name: String): RegularFileProperty = fileProperty().convention(base.file(name))
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ val Provider<out FileSystemLocation>.pathOrNull: Path?
get() = orNull?.path

fun FileSystemLocationProperty<*>.set(path: Path?) = set(path?.toFile())
fun <P : FileSystemLocationProperty<*>> P.pathProvider(path: Provider<Path?>) = apply { fileProvider(path.map { it.toFile() }) }
fun <P : FileSystemLocationProperty<*>> P.pathProvider(path: Provider<Path>) = apply { fileProvider(path.map { it.toFile() }) }

fun DirectoryProperty.convention(project: Project, path: Provider<Path?>) = convention(project.layout.dir(path.map { it.toFile() }))
fun RegularFileProperty.convention(project: Project, path: Provider<Path?>) = convention(project.layout.file(path.map { it.toFile() }))
fun DirectoryProperty.convention(project: Project, path: Provider<Path>) = convention(project.layout.dir(path.map { it.toFile() }))
fun RegularFileProperty.convention(project: Project, path: Provider<Path>) = convention(project.layout.file(path.map { it.toFile() }))
fun DirectoryProperty.convention(project: Project, path: Path) = convention(project.layout.dir(project.provider { path.toFile() }))

val Path.isLibraryJar: Boolean
Expand Down Expand Up @@ -128,9 +128,7 @@ fun Path.copyRecursivelyTo(target: Path) {
}
}

fun Path.filesMatchingRecursive(
glob: String = "*",
): List<Path> {
fun Path.filesMatchingRecursive(glob: String = "*"): List<Path> {
val matcher = fileSystem.getPathMatcher("glob:$glob")
return Files.walk(this).use { stream ->
stream.filter {
Expand Down Expand Up @@ -191,17 +189,16 @@ fun Path.contentEquals(two: InputStream, bufferSizeBytes: Int = 8192): Boolean {
return true
}

fun Path.contentEquals(file: Path, bufferSizeBytes: Int = 8192): Boolean =
file.inputStream().use { two ->
contentEquals(two, bufferSizeBytes)
}
fun Path.contentEquals(file: Path, bufferSizeBytes: Int = 8192): Boolean = file.inputStream().use { two ->
contentEquals(two, bufferSizeBytes)
}

fun Path.withDifferentExtension(ext: String): Path = resolveSibling("$nameWithoutExtension.$ext")

// Returns true if our process already owns the lock
fun acquireProcessLockWaiting(
lockFile: Path,
timeoutMs: Long = 1000L * 60 * 60 /* one hour */
timeoutMs: Long = 1000L * 60 * 60 // one hour
): Boolean {
val logger = Logging.getLogger("paperweight lock file")
val currentPid = ProcessHandle.current().pid()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private fun Project.createBuildTasks(
remapper.from(parent.configurations.named(REMAPPER_CONFIG))
remapperArgs.set(TinyRemapper.minecraftRemapArgs)

outputJar.set(buildDir.resolve("libs/${project.name}-${project.version}-reobf.jar"))
outputJar.set(layout.buildDirectory.map { it.dir("libs").file("${project.name}-${project.version}-reobf.jar") })
}

return ServerTasks(fixJarForReobf, reobfJar)
Expand Down
Loading

0 comments on commit 3be0f6c

Please sign in to comment.