diff --git a/build.gradle b/build.gradle index e9d3f8dd..b8220699 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.2-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.3-SNAPSHOT" apply false id "maven-publish" id 'com.matthewprenger.cursegradle' version '1.4.0' apply false id 'com.palantir.git-version' version '1.0.0' @@ -8,6 +8,7 @@ plugins { id 'se.bjurr.gitchangelog.git-changelog-gradle-plugin' version '1.79.0' id "com.modrinth.minotaur" version "2.+" apply false id("com.diffplug.spotless") version "6.18.0" apply false + id 'modernfix.common-conventions' apply false } architectury { @@ -16,147 +17,7 @@ architectury { ext.archives_base_name = 'modernfix' -allprojects { - apply plugin: "java" - apply plugin: "architectury-plugin" - apply plugin: "maven-publish" - apply plugin: "com.diffplug.spotless" - - spotless { - java { - removeUnusedImports() - } - } - - architectury { - compileOnly() - } - - group = 'org.embeddedt' - // extract base version from tag, generate other metadata ourselves - def details = versionDetails() - def plusIndex = details.lastTag.indexOf("+") - if(plusIndex == -1) { - plusIndex = details.lastTag.length() - } - def baseVersion = details.lastTag.substring(0, plusIndex) - def dirtyMarker = grgit.status().clean ? "" : ".dirty" - def commitHashMarker = details.commitDistance > 0 ? ("." + details.gitHash.substring(0, Math.min(4, details.gitHash.length()))) : "" - def preMarker = (details.commitDistance > 0 || !details.isCleanTag) ? ("-beta." + details.commitDistance) : "" - if(preMarker.length() > 0) { - // bump to next patch release - def versionParts = baseVersion.tokenize(".") - baseVersion = "${versionParts[0]}.${versionParts[1]}.${versionParts[2].toInteger() + 1}" - } - def versionString = "${baseVersion}${preMarker}+mc${minecraft_version}${commitHashMarker}${dirtyMarker}" - version = versionString - archivesBaseName = rootProject.archives_base_name + '-' + project.name - - sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17 - - repositories { - maven { url 'https://modmaven.dev/' } - maven { - url "https://cursemaven.com" - content { - includeGroup "curse.maven" - } - } - exclusiveContent { - forRepository { - maven { - name = "Modrinth" - url = "https://api.modrinth.com/maven" - } - } - filter { - includeGroup "maven.modrinth" - } - } - maven { - name = 'ParchmentMC' - url = 'https://maven.parchmentmc.org' - } - maven { - // Shedaniel's maven (Architectury API) - url = "https://maven.architectury.dev" - content { - includeGroup "me.shedaniel" - } - } - - maven { - // saps.dev Maven (KubeJS and Rhino) - url = "https://maven.saps.dev/minecraft" - content { - includeGroup "dev.latvian.mods" - } - } - maven { // CTM - url "https://maven.tterrag.com/" - } - maven { url 'https://maven.blamejared.com' } - repositories { - maven { - name = "Fuzs Mod Resources" - url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven/" - } - } - maven { - url 'https://maven.terraformersmc.com/releases' - } - maven { url = "https://jitpack.io" } - } -} - -configure(subprojects.findAll {it.name == "common" || it.name == "forge" || it.name == "fabric"}) { - apply plugin: "dev.architectury.loom" - - loom { - silentMojangMappingsLicense() - } - - dependencies { - minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" - mappings loom.layered() { - officialMojangMappings() - if(rootProject.hasProperty("parchment_version")) { - parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip") - } - } - } - - processResources { - def mixinFileList = [] - def mixinDirectory = file("src/main/java/org/embeddedt/modernfix/" + project.name + "/mixin") - fileTree(mixinDirectory).visit { FileVisitDetails details -> - if(details.file.isFile()) { - def fileName = mixinDirectory.relativePath(details.file).toString().replaceFirst(/\.java$/, "").replace('/', '.') - mixinFileList << fileName - } - } - - def mixinClassesStringB = new StringBuilder() - for(int i = 0; i < mixinFileList.size(); i++) { - mixinClassesStringB.append(" \"") - mixinClassesStringB.append(mixinFileList.get(i)) - mixinClassesStringB.append('"') - if(i < (mixinFileList.size() - 1)) - mixinClassesStringB.append(',') - mixinClassesStringB.append('\n') - } - - def replacements = [ - mixin_classes: mixinClassesStringB.toString() - ] - - inputs.properties replacements - def filePattern = "modernfix-" + project.name + ".mixins.json" - filesMatching(filePattern) { - expand replacements - } - } -} +apply plugin: 'modernfix.common-conventions' tasks.withType(JavaCompile).configureEach { // ensure that the encoding is set to UTF-8, no matter what the system default is @@ -203,74 +64,4 @@ tasks.register('checkCleanTag') { } } -configure(subprojects.findAll {it.name == "forge" || it.name == "fabric"}) { - apply plugin: 'com.matthewprenger.cursegradle' - apply plugin: 'com.modrinth.minotaur' - - loom { - mods { - main { // to match the default mod generated for Forge - sourceSet project.sourceSets.main - sourceSet project(':common').sourceSets.main - } - } - runs { - client { - vmArgs "-Xmx1G" - vmArgs "-Xms1G" - property("mixin.debug.export", "true") - } - } - } - - def copyJarNameConsistent = tasks.register('copyJarNameConsistent', Copy) { - from remapJar // shortcut for createJar.outputs.files - into project.file("build/libs") - rename { name -> "modernfix-" + project.name + "-latest.jar" } - } - - def copyJarToBin = tasks.register('copyJarToBin', Copy) { - from remapJar // shortcut for createJar.outputs.files - into rootProject.file("bin") - mustRunAfter "copyJarNameConsistent" - } - - tasks.build.dependsOn(copyJarToBin, copyJarNameConsistent) - - def isBeta = project.version.toString().contains("beta") - - curseforge { - if (System.getenv("CURSEFORGE_TOKEN") != null) { - apiKey = System.getenv("CURSEFORGE_TOKEN") - project { - id = "790626" - changelog = file('../CHANGELOG.md') - changelogType = "markdown" - releaseType = isBeta ? "beta" : "release" - addGameVersion project.name.capitalize() - gameVersionStrings.addAll(supported_minecraft_versions.tokenize(",")) - mainArtifact remapJar - } - } - } - - modrinth { - token = System.getenv("MODRINTH_TOKEN") - projectId = "modernfix" // This can be the project ID or the slug. Either will work! - versionType = isBeta ? "beta" : "release" // This is the default -- can also be `beta` or `alpha` - uploadFile = remapJar - gameVersions = supported_minecraft_versions.tokenize(",") - loaders = project.name.equals("forge") ? ["forge", "neoforge"] : ["fabric"] - changelog.set(provider { file("CHANGELOG.md").getText('UTF-8') }) - } - - tasks.curseforge.dependsOn(rootProject.generateChangelog) - tasks.modrinth.dependsOn(rootProject.generateChangelog) - - tasks.register('publishToModSites') { - publishToModSites.dependsOn(tasks.modrinth) - publishToModSites.dependsOn(tasks.curseforge) - } -} - println "ModernFix: " + version diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 00000000..1957c339 --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,3 @@ +plugins { + id 'groovy-gradle-plugin' +} \ No newline at end of file diff --git a/buildSrc/settings.gradle b/buildSrc/settings.gradle new file mode 100644 index 00000000..e69de29b diff --git a/buildSrc/src/main/groovy/modernfix.common-conventions.gradle b/buildSrc/src/main/groovy/modernfix.common-conventions.gradle new file mode 100644 index 00000000..3c3d5e07 --- /dev/null +++ b/buildSrc/src/main/groovy/modernfix.common-conventions.gradle @@ -0,0 +1,81 @@ +plugins { + id 'java' + id 'architectury-plugin' + id 'maven-publish' + id 'com.diffplug.spotless' +} + +spotless { + java { + removeUnusedImports() + } +} + +architectury { + compileOnly() +} + +group = 'org.embeddedt' +// extract base version from tag, generate other metadata ourselves +def details = versionDetails() +def plusIndex = details.lastTag.indexOf("+") +if(plusIndex == -1) { + plusIndex = details.lastTag.length() +} +def baseVersion = details.lastTag.substring(0, plusIndex) +def dirtyMarker = grgit.status().clean ? "" : ".dirty" +def commitHashMarker = details.commitDistance > 0 ? ("." + details.gitHash.substring(0, Math.min(4, details.gitHash.length()))) : "" +def preMarker = (details.commitDistance > 0 || !details.isCleanTag) ? ("-beta." + details.commitDistance) : "" +if(preMarker.length() > 0) { + // bump to next patch release + def versionParts = baseVersion.tokenize(".") + baseVersion = "${versionParts[0]}.${versionParts[1]}.${versionParts[2].toInteger() + 1}" +} +def versionString = "${baseVersion}${preMarker}+mc${minecraft_version}${commitHashMarker}${dirtyMarker}" +version = versionString +archivesBaseName = rootProject.archives_base_name + '-' + project.name + +sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17 + +repositories { + maven { url 'https://modmaven.dev/' } + maven { + url "https://cursemaven.com" + content { + includeGroup "curse.maven" + } + } + maven { + name = 'ParchmentMC' + url = 'https://maven.parchmentmc.org' + } + maven { + // Shedaniel's maven (Architectury API) + url = "https://maven.architectury.dev" + content { + includeGroup "me.shedaniel" + } + } + + maven { + // saps.dev Maven (KubeJS and Rhino) + url = "https://maven.saps.dev/minecraft" + content { + includeGroup "dev.latvian.mods" + } + } + maven { // CTM + url "https://maven.tterrag.com/" + } + maven { url 'https://maven.blamejared.com' } + repositories { + maven { + name = "Fuzs Mod Resources" + url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven/" + } + } + maven { + url 'https://maven.terraformersmc.com/releases' + } + maven { url = "https://jitpack.io" } +} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/modernfix.mod-common-conventions.gradle b/buildSrc/src/main/groovy/modernfix.mod-common-conventions.gradle new file mode 100644 index 00000000..3362ce37 --- /dev/null +++ b/buildSrc/src/main/groovy/modernfix.mod-common-conventions.gradle @@ -0,0 +1,52 @@ +plugins { + id 'modernfix.common-conventions' + id 'dev.architectury.loom' +} + +loom { + silentMojangMappingsLicense() + accessWidenerPath = file("${rootDir}/common/src/main/resources/modernfix.accesswidener") +} + +dependencies { + minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" + mappings loom.layered() { + officialMojangMappings() + if(rootProject.hasProperty("parchment_version")) { + parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip") + } + } +} + +tasks { + processResources { + def mixinFileList = [] + def mixinDirectory = file("src/main/java/org/embeddedt/modernfix/" + project.name + "/mixin") + fileTree(mixinDirectory).visit { FileVisitDetails details -> + if(details.file.isFile()) { + def fileName = mixinDirectory.relativePath(details.file).toString().replaceFirst(/\.java$/, "").replace('/', '.') + mixinFileList << fileName + } + } + + def mixinClassesStringB = new StringBuilder() + for(int i = 0; i < mixinFileList.size(); i++) { + mixinClassesStringB.append(" \"") + mixinClassesStringB.append(mixinFileList.get(i)) + mixinClassesStringB.append('"') + if(i < (mixinFileList.size() - 1)) + mixinClassesStringB.append(',') + mixinClassesStringB.append('\n') + } + + def replacements = [ + mixin_classes: mixinClassesStringB.toString() + ] + + inputs.properties replacements + def filePattern = "modernfix-" + project.name + ".mixins.json" + filesMatching(filePattern) { + expand replacements + } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/modernfix.platform-conventions.gradle b/buildSrc/src/main/groovy/modernfix.platform-conventions.gradle new file mode 100644 index 00000000..5753965e --- /dev/null +++ b/buildSrc/src/main/groovy/modernfix.platform-conventions.gradle @@ -0,0 +1,69 @@ +plugins { + id 'com.matthewprenger.cursegradle' + id 'com.modrinth.minotaur' +} + +loom { + mods { + main { // to match the default mod generated for Forge + sourceSet project.sourceSets.main + sourceSet project(':common').sourceSets.main + } + } + runs { + client { + vmArgs "-Xmx1G" + vmArgs "-Xms1G" + property("mixin.debug.export", "true") + } + } +} + +def copyJarNameConsistent = tasks.register('copyJarNameConsistent', Copy) { + from remapJar // shortcut for createJar.outputs.files + into project.file("build/libs") + rename { name -> "modernfix-" + project.name + "-latest.jar" } +} + +def copyJarToBin = tasks.register('copyJarToBin', Copy) { + from remapJar // shortcut for createJar.outputs.files + into rootProject.file("bin") + mustRunAfter "copyJarNameConsistent" +} + +tasks.build.dependsOn(copyJarToBin, copyJarNameConsistent) + +def isBeta = project.version.toString().contains("beta") + +curseforge { + if (System.getenv("CURSEFORGE_TOKEN") != null) { + apiKey = System.getenv("CURSEFORGE_TOKEN") + project { + id = "790626" + changelog = file('../CHANGELOG.md') + changelogType = "markdown" + releaseType = isBeta ? "beta" : "release" + addGameVersion project.name.capitalize() + gameVersionStrings.addAll(supported_minecraft_versions.tokenize(",")) + mainArtifact remapJar + } + } +} + +modrinth { + token = System.getenv("MODRINTH_TOKEN") + projectId = "modernfix" // This can be the project ID or the slug. Either will work! + versionType = isBeta ? "beta" : "release" // This is the default -- can also be `beta` or `alpha` + uploadFile = remapJar + gameVersions = supported_minecraft_versions.tokenize(",") + loaders = [project.name] + changelog.set(provider { file("CHANGELOG.md").getText('UTF-8') }) +} + +tasks.curseforge.dependsOn(rootProject.generateChangelog) +tasks.modrinth.dependsOn(rootProject.generateChangelog) + +tasks.register('publishToModSites') { + publishToModSites.dependsOn(tasks.modrinth) + publishToModSites.dependsOn(tasks.curseforge) +} \ No newline at end of file diff --git a/common/build.gradle b/common/build.gradle index 33cd3594..fceb26c9 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,9 +1,9 @@ -architectury { - common(rootProject.enabled_platforms.split(",")) +plugins { + id "modernfix.mod-common-conventions" } -loom { - accessWidenerPath = file("src/main/resources/modernfix.accesswidener") +architectury { + common(rootProject.enabled_platforms.split(",")) } ext.jei_minecraft_version = "1.19.4" /* temporary, till 1.20 releases */ diff --git a/fabric/build.gradle b/fabric/build.gradle index b772ea75..fd5f0652 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,6 +1,8 @@ plugins { id "com.github.johnrengelman.shadow" version "7.1.2" id 'com.adarshr.test-logger' version '3.2.0' + id "modernfix.mod-common-conventions" + id "modernfix.platform-conventions" } architectury { @@ -8,10 +10,6 @@ architectury { fabric() } -loom { - accessWidenerPath = project(":common").loom.accessWidenerPath -} - configurations { common shadowCommon // Don't use shadow from the shadow plugin since it *excludes* files. diff --git a/fabric/testmod/build.gradle b/fabric/testmod/build.gradle index 228b8a61..08d3d446 100644 --- a/fabric/testmod/build.gradle +++ b/fabric/testmod/build.gradle @@ -1,4 +1,6 @@ -apply plugin: "dev.architectury.loom" +plugins { + id 'dev.architectury.loom' +} loom { accessWidenerPath = project(":common").loom.accessWidenerPath diff --git a/forge/build.gradle b/forge/build.gradle index dcf23917..5487310b 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -1,5 +1,7 @@ plugins { id "com.github.johnrengelman.shadow" version "7.1.2" + id "modernfix.mod-common-conventions" + id "modernfix.platform-conventions" } architectury { @@ -8,8 +10,6 @@ architectury { } loom { - accessWidenerPath = project(":common").loom.accessWidenerPath - forge { convertAccessWideners = true extraAccessWideners.add loom.accessWidenerPath.get().asFile.name @@ -108,9 +108,8 @@ jar { //"Specification-Vendor": "modernfix authors", "Specification-Version" : "1", // We are version 1 of ourselves "Implementation-Title" : project.name, - "Implementation-Version" : project.jar.archiveVersion, + "Implementation-Version" : project.jar.archiveVersion //"Implementation-Vendor": "modernfix authors", - "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) } } diff --git a/test_agent/build.gradle b/test_agent/build.gradle index 2141b87d..bd589bbd 100644 --- a/test_agent/build.gradle +++ b/test_agent/build.gradle @@ -1,6 +1,7 @@ plugins { //id 'com.github.johnrengelman.shadow' version '7.1.2' id 'java' + id 'modernfix.common-conventions' } group 'org.embeddedt'