diff --git a/LICENSE.md b/LICENSE.md index 518a2732c..af23f9c4b 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2021-2023 Jozufozu +Copyright (c) 2021-2024 Jozufozu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 070b9c27d..335241b39 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,5 +1,4 @@ plugins { - id("groovy-gradle-plugin") id("java-gradle-plugin") kotlin("jvm") version "1.9.20" `kotlin-dsl` @@ -36,6 +35,10 @@ gradlePlugin { id = "flywheel.transitive-source-sets" implementationClass = "com.jozufozu.gradle.transitive.TransitiveSourceSetsPlugin" } + create("subprojectPlugin") { + id = "flywheel.subproject" + implementationClass = "com.jozufozu.gradle.subproject.SubprojectPlugin" + } } } diff --git a/buildSrc/src/main/groovy/flywheel.java.gradle b/buildSrc/src/main/groovy/flywheel.java.gradle deleted file mode 100644 index 876f16869..000000000 --- a/buildSrc/src/main/groovy/flywheel.java.gradle +++ /dev/null @@ -1,54 +0,0 @@ -boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equalsIgnoreCase('false') -String buildNumber = System.getenv('BUILD_NUMBER') - -group = 'com.jozufozu.flywheel' -version = mod_version + (dev && buildNumber != null ? "-${buildNumber}" : '') - -base { - archivesName = "flywheel-${name}-${artifact_minecraft_version}" -} - -java { - JavaVersion javaVersion = JavaVersion.toVersion(java_version) - sourceCompatibility = javaVersion - targetCompatibility = javaVersion - - toolchain.languageVersion = JavaLanguageVersion.of(java_version) - - withSourcesJar() - withJavadocJar() -} - -// make builds reproducible -tasks.withType(AbstractArchiveTask).configureEach { - preserveFileTimestamps = false - reproducibleFileOrder = true -} - -// module metadata is often broken on multi-platform projects -tasks.withType(GenerateModuleMetadata).configureEach { - enabled = false -} - -tasks.withType(JavaCompile).configureEach { JavaCompile javaCompile -> - javaCompile.options.encoding = 'UTF-8' - javaCompile.options.release = Integer.parseInt(java_version) - javaCompile.options.compilerArgs = ['-Xdiags:verbose'] -} - -tasks.withType(Jar).configureEach { Jar jar -> - addLicense(jar) -} - -tasks.named('javadoc', Javadoc).configure { Javadoc javadoc -> - javadoc.source sourceSets.main.allJava - // prevent java 8's strict doclint for javadocs from failing builds - javadoc.options.optionFiles(rootProject.file('javadoc-options.txt')) - javadoc.options.encoding = 'UTF-8' -} - -static void addLicense(Jar jarTask) { - jarTask.from('LICENSE.md') { - rename '(.*)\\.(.*)', '$1_' + jarTask.archiveBaseName + '.$2' - } -} diff --git a/buildSrc/src/main/groovy/flywheel.subproject.gradle b/buildSrc/src/main/groovy/flywheel.subproject.gradle deleted file mode 100644 index d206a8758..000000000 --- a/buildSrc/src/main/groovy/flywheel.subproject.gradle +++ /dev/null @@ -1,76 +0,0 @@ -loom { - silentMojangMappingsLicense() - - mixin { - defaultRefmapName = "flywheel.refmap.json" - } -} - -repositories { - mavenCentral() - maven { - name = 'ParchmentMC' - url = 'https://maven.parchmentmc.org' - } - maven { - name 'tterrag maven' - url 'https://maven.tterrag.com/' - } - maven { - url 'https://www.cursemaven.com' - content { - includeGroup "curse.maven" - } - } - maven { - name = "Modrinth" - url = "https://api.modrinth.com/maven" - content { - includeGroup "maven.modrinth" - } - } -} - -dependencies { - minecraft "com.mojang:minecraft:${minecraft_version}" - mappings(loom.layered() { - officialMojangMappings() - parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip") - }) - - api 'com.google.code.findbugs:jsr305:3.0.2' -} - -tasks.withType(ProcessResources).configureEach { - var replaceProperties = [ - mod_id : mod_id, - mod_name : mod_name, - mod_description : mod_description, - mod_license : mod_license, - mod_sources : mod_sources, - mod_issues : mod_issues, - mod_homepage : mod_homepage, - mod_version : mod_version, - minecraft_semver_version_range: minecraft_semver_version_range, - minecraft_maven_version_range : minecraft_maven_version_range, - fabric_api_version_range : fabric_api_version_range, - forge_version_range : forge_version_range, - ] - inputs.properties replaceProperties - - filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml']) { - expand replaceProperties - } -} - -publishing { - repositories { - maven { - url "file://${rootProject.projectDir}/mcmodsrepo" - } - - if (project.hasProperty('mavendir')) { - maven { url rootProject.file(property('mavendir')) } - } - } -} diff --git a/buildSrc/src/main/kotlin/com/jozufozu/gradle/subproject/SubprojectPlugin.kt b/buildSrc/src/main/kotlin/com/jozufozu/gradle/subproject/SubprojectPlugin.kt new file mode 100644 index 000000000..02419f11a --- /dev/null +++ b/buildSrc/src/main/kotlin/com/jozufozu/gradle/subproject/SubprojectPlugin.kt @@ -0,0 +1,182 @@ +package com.jozufozu.gradle.subproject + +import net.fabricmc.loom.api.LoomGradleExtensionAPI +import org.gradle.api.JavaVersion +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.plugins.BasePluginExtension +import org.gradle.api.plugins.JavaPluginExtension +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.tasks.GenerateModuleMetadata +import org.gradle.api.tasks.bundling.AbstractArchiveTask +import org.gradle.api.tasks.compile.JavaCompile +import org.gradle.api.tasks.javadoc.Javadoc +import org.gradle.jvm.tasks.Jar +import org.gradle.jvm.toolchain.JavaLanguageVersion +import org.gradle.kotlin.dsl.assign +import org.gradle.kotlin.dsl.maven +import org.gradle.kotlin.dsl.provideDelegate +import org.gradle.kotlin.dsl.the +import org.gradle.language.jvm.tasks.ProcessResources + + +class SubprojectPlugin: Plugin { + override fun apply(project: Project) { + setBaseProperties(project) + setupJava(project) + addRepositories(project) + setupLoom(project) + setupDependencies(project) + configureTasks(project) + setupPublishing(project) + } + + private fun setBaseProperties(project: Project) { + val dev = System.getenv("RELEASE")?.contentEquals("false", true) ?: true + val buildNumber = System.getenv("BUILD_NUMBER") + + val mod_version: String by project + project.group = "com.jozufozu.flywheel" + project.version = mod_version + if (dev && buildNumber != null) "-${buildNumber}" else "" + + val artifact_minecraft_version: String by project + project.the().archivesName = "flywheel-${project.name}-${artifact_minecraft_version}" + } + + @Suppress("UnstableApiUsage") + private fun setupLoom(project: Project) { + val loom = project.the() + loom.silentMojangMappingsLicense() + + loom.mixin.defaultRefmapName = "flywheel.refmap.json" + } + + private fun setupJava(project: Project) { + val java_version: String by project + + project.the().apply { + val javaVersion = JavaVersion.toVersion(java_version) + sourceCompatibility = javaVersion + targetCompatibility = javaVersion + + toolchain.languageVersion = JavaLanguageVersion.of(java_version) + + withSourcesJar() + withJavadocJar() + } + } + + private fun addRepositories(project: Project) { + project.repositories.apply { + mavenCentral() + maven("https://maven.parchmentmc.org") { + name = "ParchmentMC" + } + maven("https://maven.tterrag.com/") { + name = "tterrag maven" + } + maven("https://www.cursemaven.com") { + name = "CurseMaven" + content { + includeGroup("curse.maven") + } + } + maven("https://api.modrinth.com/maven") { + name = "Modrinth" + content { + includeGroup("maven.modrinth") + } + } + } + } + + @Suppress("UnstableApiUsage") + private fun setupDependencies(project: Project) { + project.dependencies.apply { + val minecraft_version: String by project + val parchment_version: String by project + val loom = project.the() + + add("minecraft", "com.mojang:minecraft:${minecraft_version}") + + add("mappings", loom.layered { + officialMojangMappings() + parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip") + }) + + add("api", "com.google.code.findbugs:jsr305:3.0.2") + } + } + + private fun configureTasks(project: Project) { + val java_version: String by project + + project.tasks.apply { + // make builds reproducible + withType(AbstractArchiveTask::class.java).configureEach { + isPreserveFileTimestamps = false + isReproducibleFileOrder = true + } + + // module metadata is often broken on multi-platform projects + withType(GenerateModuleMetadata::class.java).configureEach { + enabled = false + } + + withType(JavaCompile::class.java).configureEach { + options.encoding = "UTF-8" + options.release = Integer.parseInt(java_version) + options.compilerArgs.add("-Xdiags:verbose") + } + + withType(Jar::class.java).configureEach { + from("${project.rootDir}/LICENSE.md") { + into("META-INF") + } + } + + withType(Javadoc::class.java).configureEach { + options.optionFiles(project.rootProject.file("javadoc-options.txt")) + options.encoding = "UTF-8" + } + + val replaceProperties = processResourcesExpandProperties.associateWith { project.property(it) as String } + + withType(ProcessResources::class.java).configureEach { + inputs.properties(replaceProperties) + + filesMatching(processResourcesExpandFiles) { + expand(replaceProperties) + } + } + } + } + + private fun setupPublishing(project: Project) { + project.the().repositories.apply { + maven("file://${project.rootProject.projectDir}/mcmodsrepo") + + if (project.hasProperty("mavendir")) { + maven(project.rootProject.file(project.property("mavendir") as String)) + } + } + } +} + +val processResourcesExpandFiles = listOf("pack.mcmeta", "fabric.mod.json", "META-INF/mods.toml") + +val processResourcesExpandProperties = listOf( + "mod_id", + "mod_name", + "mod_description", + "mod_license", + "mod_sources", + "mod_issues", + "mod_homepage", + "mod_version", + "minecraft_semver_version_range", + "minecraft_maven_version_range", + "fabric_api_version_range", + "forge_version_range", +) + diff --git a/common/build.gradle b/common/build.gradle index 8ac5231cb..c2f59a552 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -3,7 +3,6 @@ plugins { id 'java' id 'maven-publish' id 'dev.architectury.loom' - id 'flywheel.java' id 'flywheel.package-infos' id 'flywheel.subproject' id 'flywheel.jar-sets' diff --git a/fabric/build.gradle b/fabric/build.gradle index 7b3fbb111..eda0a1e57 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -3,7 +3,6 @@ plugins { id 'java' id 'maven-publish' id 'dev.architectury.loom' - id 'flywheel.java' id 'flywheel.package-infos' id 'flywheel.subproject' id 'flywheel.platform' diff --git a/forge/build.gradle b/forge/build.gradle index 04ec7eab4..707960030 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -3,7 +3,6 @@ plugins { id 'java' id 'maven-publish' id 'dev.architectury.loom' - id 'flywheel.java' id 'flywheel.package-infos' id 'flywheel.subproject' id 'flywheel.platform'