From c6364727a00d87aba2ddaa80ae2cc14dfae9b830 Mon Sep 17 00:00:00 2001 From: modmuss Date: Wed, 18 Dec 2024 18:22:30 +0000 Subject: [PATCH] Some gradle deprecation fixes (#4308) --- build.gradle | 4 +-- gradle/module-validation.gradle | 51 ++++++++++++++++++++++++--------- gradle/package-info.gradle | 11 +++++-- 3 files changed, 49 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index 9d35401302..ae35a7cfb6 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { id "fabric-loom" version "1.9.2" apply false id "com.diffplug.spotless" version "6.20.0" id "org.ajoberstar.grgit" version "5.2.2" - id "me.modmuss50.remotesign" version "0.4.0" apply false + id "me.modmuss50.remotesign" version "0.5.0" apply false id "me.modmuss50.mod-publish-plugin" version "0.4.5" } @@ -388,7 +388,7 @@ javadoc { classpath = files(sourceSets.main.compileClasspath, sourceSets.client.compileClasspath) include("**/api/**") - failOnError true + failOnError = true } tasks.register('javadocJar', Jar) { diff --git a/gradle/module-validation.gradle b/gradle/module-validation.gradle index 5f48355968..2680409bd0 100644 --- a/gradle/module-validation.gradle +++ b/gradle/module-validation.gradle @@ -13,7 +13,7 @@ subprojects { } // Create the task - task validateModules(type: ValidateModuleTask) + tasks.register("validateModules", ValidateModuleTask) } /** @@ -26,38 +26,63 @@ subprojects { * } * } */ -class ValidateModuleTask extends DefaultTask { +abstract class ValidateModuleTask extends DefaultTask { + @InputFile + @Optional + abstract RegularFileProperty getFmj() + + @InputFile + @Optional + abstract RegularFileProperty getClientFmj() + + @Input + abstract Property getProjectName() + + @Input + abstract Property getProjectPath() + + @Input + abstract Property getLoaderVersion() + ValidateModuleTask() { group = "verification" // Hook up validation to check task project.tasks.check.dependsOn(this) + + fmj.set(project.file("src/main/resources/fabric.mod.json")) + clientFmj.set(project.file("src/client/resources/fabric.mod.json")) + + projectName.set(project.name) + projectPath.set(project.path) + loaderVersion.set(project.loader_version) } @TaskAction void validate() { def clientOnlyMod = false - def file = (project.file("src/main/resources/fabric.mod.json") as File) + + def file = fmj.get().asFile if (!file.exists()) { - file = (project.file("src/client/resources/fabric.mod.json") as File) + file = clientFmj.get().asFile clientOnlyMod = true } def json = new JsonSlurper().parse(file) if (json.custom == null) { - throw new GradleException("Module ${project} does not have a custom value containing module lifecycle!") + throw new GradleException("Module ${projectName.get()} does not have a custom value containing module lifecycle!") } def moduleLifecycle = json.custom.get("fabric-api:module-lifecycle") if (moduleLifecycle == null) { - throw new GradleException("Module ${project} does not have module lifecycle in custom values!") + throw new GradleException("Module ${projectName.get()} does not have module lifecycle in custom values!") } if (!moduleLifecycle instanceof String) { - throw new GradleException("Module ${project} has an invalid module lifecycle value. The value must be a string but read a ${moduleLifecycle.class}") + throw new GradleException("Module ${projectName.get()} has an invalid module lifecycle value. The value must be a string but read a ${moduleLifecycle.class}") } // Validate the lifecycle value @@ -66,20 +91,20 @@ class ValidateModuleTask extends DefaultTask { case "experimental": break case "deprecated": - if (!project.path.startsWith(":deprecated")) { - throw new GradleException("Deprecated module ${project} must be in the deprecated sub directory.") + if (!projectPath.get().startsWith(":deprecated")) { + throw new GradleException("Deprecated module ${projectName.get()} must be in the deprecated sub directory.") } break default: - throw new GradleException("Module ${project} has an invalid module lifecycle ${json.custom.get('fabric-api:module-lifecycle')}") + throw new GradleException("Module ${projectName.get()} has an invalid module lifecycle ${json.custom.get('fabric-api:module-lifecycle')}") } if (json.depends == null) { - throw new GradleException("Module ${project} does not have a depends value!") + throw new GradleException("Module ${projectName.get()} does not have a depends value!") } - if (json.depends.fabricloader != ">=${project.loader_version}") { - throw new GradleException("Module ${project} does not have a valid fabricloader value! Got \"${json.depends.fabricloader}\" but expected \">=${project.loader_version}\"") + if (json.depends.fabricloader != ">=${loaderVersion.get()}") { + throw new GradleException("Module ${projectName.get()} does not have a valid fabricloader value! Got \"${json.depends.fabricloader}\" but expected \">=${project.loader_version}\"") } } } diff --git a/gradle/package-info.gradle b/gradle/package-info.gradle index 256f9c3c7f..10eacfe453 100644 --- a/gradle/package-info.gradle +++ b/gradle/package-info.gradle @@ -27,10 +27,13 @@ for (def sourceSet in [ clean.dependsOn cleanTask } -class GenerateImplPackageInfos extends DefaultTask { +abstract class GenerateImplPackageInfos extends DefaultTask { @InputFile File header + @Input + abstract Property getProjectName() + @SkipWhenEmpty @InputDirectory final DirectoryProperty sourceRoot = project.objects.directoryProperty() @@ -38,6 +41,10 @@ class GenerateImplPackageInfos extends DefaultTask { @OutputDirectory final DirectoryProperty outputDir = project.objects.directoryProperty() + GenerateImplPackageInfos() { + projectName.set(project.name) + } + @TaskAction def run() { def output = outputDir.get().asFile.toPath() @@ -66,7 +73,7 @@ class GenerateImplPackageInfos extends DefaultTask { def packageName = relativePath.toString().replace(File.separator, '.') it.write("""$headerText |/** - | * Implementation code for ${project.name}. + | * Implementation code for ${projectName.get()}. | */ |@ApiStatus.Internal |package $packageName;