From 36362170c7a9743006fcd6f2dc80a6f11a37dcc8 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Mon, 22 Apr 2024 11:51:28 -0700 Subject: [PATCH] Graidiomatic - Move common build script stuff to buildSrc - Set ideaSyncTask finalizedBy generatePackageInfos directly in package-infos.gradle - Enable loom multiproject optimization, though not sure if it makes a difference for us yet --- build.gradle | 224 +--------------------- buildSrc/build.gradle | 2 + {gradle => buildSrc}/package-infos.gradle | 4 + buildSrc/platforms.gradle | 67 +++++++ buildSrc/simple-java.gradle | 58 ++++++ buildSrc/subprojects.gradle | 72 +++++++ common/build.gradle | 11 ++ fabric/build.gradle | 12 ++ forge/build.gradle | 12 ++ gradle.properties | 1 + 10 files changed, 243 insertions(+), 220 deletions(-) create mode 100644 buildSrc/build.gradle rename {gradle => buildSrc}/package-infos.gradle (96%) create mode 100644 buildSrc/platforms.gradle create mode 100644 buildSrc/simple-java.gradle create mode 100644 buildSrc/subprojects.gradle diff --git a/build.gradle b/build.gradle index 2a823f262..9f9460aad 100644 --- a/build.gradle +++ b/build.gradle @@ -1,230 +1,14 @@ plugins { id 'idea' - // make sure gradle loads the same arch plugin across all subprojects + id 'java' + id 'maven-publish' id 'dev.architectury.loom' apply false } +apply from: rootProject.file('buildSrc/simple-java.gradle') + println("Java: ${System.getProperty('java.version')}, JVM: ${System.getProperty('java.vm.version')} (${System.getProperty('java.vendor')}), Arch: ${System.getProperty('os.arch')}") -allprojects { - // Need to setup the java plugin for all projects so that our subprojects can find an output directory - apply plugin: 'java' - apply plugin: 'maven-publish' - - 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.named('jar', Jar).configure { Jar jar -> - archiveClassifier = '' - addLicense(jar) - } - - tasks.named('sourcesJar', Jar).configure { 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.addStringOption('Xdoclint:none', '-quiet') - } -} - -subprojects { - apply plugin: 'dev.architectury.loom' - - loom { - silentMojangMappingsLicense() - } - - 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' - } - - processResources { - 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')) } - } - } - } - - apply from: rootProject.file('gradle/package-infos.gradle') - - ideaSyncTask.finalizedBy(generatePackageInfos) -} - -// Common configuration for platform dependent subprojects. -for (final String subprojectName in [':fabric', ':forge']) { - project(subprojectName) { - evaluationDependsOn(':common') - - loom { - runs { - client { - ideConfigGenerated true - - // Turn on our own debug flags - property 'flw.dumpShaderSource', 'true' - property 'flw.debugMemorySafety', 'true' - - // Turn on mixin debug flags - property 'mixin.debug.export', 'true' - property 'mixin.debug.verbose', 'true' - - // 720p baby! - programArgs '--width', '1280', '--height', '720' - } - - // We're a client mod, but we need to make sure we correctly render when playing on a server. - server { - ideConfigGenerated true - programArgs '--nogui' - } - } - } - - tasks.named('processResources', ProcessResources).configure { ProcessResources processResources -> - processResources.from project(':common').tasks.named('processResources', ProcessResources).get().source - } - - tasks.named('compileJava', JavaCompile).configure { JavaCompile compileJava -> - compileJava.source project(':common').tasks.named('compileJava', JavaCompile).get().source - excludeDuplicatePackageInfos(compileJava) - } - - tasks.named('javadoc', Javadoc).configure { Javadoc javadoc -> - javadoc.source project(':common').tasks.named('javadoc', Javadoc).get().source - excludeDuplicatePackageInfos(javadoc) - } - - tasks.named('jar', Jar).configure { Jar jar -> - excludeDuplicatePackageInfos(jar) - } - - tasks.named('sourcesJar', Jar).configure { Jar jar -> - def commonSources = project(':common').tasks.named('sourcesJar', Jar) - dependsOn commonSources - jar.from zipTree(commonSources.flatMap { it.archiveFile }) - - excludeDuplicatePackageInfos(jar) - } - } -} - -static void addLicense(Jar jarTask) { - jarTask.from('LICENSE.md') { - rename '(.*)\\.(.*)', '$1_' + jarTask.archiveBaseName + '.$2' - } -} - -// We have duplicate packages between the common and platform dependent subprojects. -// In theory the package-info.java files should be identical, so just take the first one we find. -static void excludeDuplicatePackageInfos(AbstractCopyTask copyTask) { - copyTask.filesMatching('**/package-info.java') { - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - } -} - -// The compile/javadoc tasks have a different base type that isn't so smart about exclusion handling. -static void excludeDuplicatePackageInfos(SourceTask sourceTask) { - // FIXME: actually scan the files and exclude the duplicates - // may be tough because the files have absolute paths - sourceTask.exclude('**/package-info.java') -} - idea { // Tell IDEA to always download sources/javadoc artifacts from maven. module { diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 000000000..a42435e5e --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,2 @@ + +// TODO: port stuff to convention plugins diff --git a/gradle/package-infos.gradle b/buildSrc/package-infos.gradle similarity index 96% rename from gradle/package-infos.gradle rename to buildSrc/package-infos.gradle index b6877b240..1fd334292 100644 --- a/gradle/package-infos.gradle +++ b/buildSrc/package-infos.gradle @@ -20,6 +20,10 @@ def setupGeneratePackageInfos(SourceSet sourceSet) { } sourceSet.java.srcDir task + tasks.named('ideaSyncTask').configure { + finalizedBy task + } + def cleanTask = tasks.register(sourceSet.getTaskName('clean', 'PackageInfos'), Delete) { group = 'flywheel' delete file("src/$sourceSetName/generatedPackageInfos") diff --git a/buildSrc/platforms.gradle b/buildSrc/platforms.gradle new file mode 100644 index 000000000..f8200edaf --- /dev/null +++ b/buildSrc/platforms.gradle @@ -0,0 +1,67 @@ +evaluationDependsOn(':common') + +loom { + runs { + client { + ideConfigGenerated true + + // Turn on our own debug flags + property 'flw.dumpShaderSource', 'true' + property 'flw.debugMemorySafety', 'true' + + // Turn on mixin debug flags + property 'mixin.debug.export', 'true' + property 'mixin.debug.verbose', 'true' + + // 720p baby! + programArgs '--width', '1280', '--height', '720' + } + + // We're a client mod, but we need to make sure we correctly render when playing on a server. + server { + ideConfigGenerated true + programArgs '--nogui' + } + } +} + +tasks.named('processResources', ProcessResources).configure { ProcessResources processResources -> + processResources.from project(':common').tasks.named('processResources', ProcessResources).get().source +} + +tasks.named('compileJava', JavaCompile).configure { JavaCompile compileJava -> + compileJava.source project(':common').tasks.named('compileJava', JavaCompile).get().source + excludeDuplicatePackageInfos(compileJava) +} + +tasks.named('javadoc', Javadoc).configure { Javadoc javadoc -> + javadoc.source project(':common').tasks.named('javadoc', Javadoc).get().source + excludeDuplicatePackageInfos(javadoc) +} + +tasks.named('jar', Jar).configure { Jar jar -> + excludeDuplicatePackageInfos(jar) +} + +tasks.named('sourcesJar', Jar).configure { Jar jar -> + def commonSources = project(':common').tasks.named('sourcesJar', Jar) + dependsOn commonSources + jar.from zipTree(commonSources.flatMap { it.archiveFile }) + + excludeDuplicatePackageInfos(jar) +} + +// We have duplicate packages between the common and platform dependent subprojects. +// In theory the package-info.java files should be identical, so just take the first one we find. +static void excludeDuplicatePackageInfos(AbstractCopyTask copyTask) { + copyTask.filesMatching('**/package-info.java') { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + } +} + +// The compile/javadoc tasks have a different base type that isn't so smart about exclusion handling. +static void excludeDuplicatePackageInfos(SourceTask sourceTask) { + // FIXME: actually scan the files and exclude the duplicates + // may be tough because the files have absolute paths + sourceTask.exclude('**/package-info.java') +} diff --git a/buildSrc/simple-java.gradle b/buildSrc/simple-java.gradle new file mode 100644 index 000000000..3c74a001a --- /dev/null +++ b/buildSrc/simple-java.gradle @@ -0,0 +1,58 @@ +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.named('jar', Jar).configure { Jar jar -> + archiveClassifier = '' + addLicense(jar) +} + +tasks.named('sourcesJar', Jar).configure { 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.addStringOption('Xdoclint:none', '-quiet') +} + +static void addLicense(Jar jarTask) { + jarTask.from('LICENSE.md') { + rename '(.*)\\.(.*)', '$1_' + jarTask.archiveBaseName + '.$2' + } +} diff --git a/buildSrc/subprojects.gradle b/buildSrc/subprojects.gradle new file mode 100644 index 000000000..967b3d6c4 --- /dev/null +++ b/buildSrc/subprojects.gradle @@ -0,0 +1,72 @@ +loom { + silentMojangMappingsLicense() +} + +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' +} + +processResources { + 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/common/build.gradle b/common/build.gradle index 9b27890cf..076a9c801 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,3 +1,14 @@ +plugins { + id 'idea' + id 'java' + id 'maven-publish' + id 'dev.architectury.loom' +} + +apply from: rootProject.file('buildSrc/simple-java.gradle') +apply from: rootProject.file('buildSrc/subprojects.gradle') +apply from: rootProject.file('buildSrc/package-infos.gradle') + dependencies { modCompileOnly "net.fabricmc:fabric-loader:${fabric_loader_version}" diff --git a/fabric/build.gradle b/fabric/build.gradle index ec6a423a2..f04a6c6ad 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,3 +1,15 @@ +plugins { + id 'idea' + id 'java' + id 'maven-publish' + id 'dev.architectury.loom' +} + +apply from: rootProject.file('buildSrc/simple-java.gradle') +apply from: rootProject.file('buildSrc/subprojects.gradle') +apply from: rootProject.file('buildSrc/platforms.gradle') +apply from: rootProject.file('buildSrc/package-infos.gradle') + dependencies { compileOnly project(path: ':common', configuration: 'namedElements') diff --git a/forge/build.gradle b/forge/build.gradle index 239e9ce34..e33ef4ae1 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -1,3 +1,15 @@ +plugins { + id 'idea' + id 'java' + id 'maven-publish' + id 'dev.architectury.loom' +} + +apply from: rootProject.file('buildSrc/simple-java.gradle') +apply from: rootProject.file('buildSrc/subprojects.gradle') +apply from: rootProject.file('buildSrc/platforms.gradle') +apply from: rootProject.file('buildSrc/package-infos.gradle') + loom { forge { mixinConfig 'flywheel.backend.mixins.json' diff --git a/gradle.properties b/gradle.properties index b39b08802..04eec2432 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,6 @@ org.gradle.jvmargs = -Xmx3G org.gradle.daemon = false +fabric.loom.multiProjectOptimisation=true # Mod metadata mod_id = flywheel