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
This commit is contained in:
Jozufozu 2024-04-22 11:51:28 -07:00
parent 3ccb4eb9a1
commit 36362170c7
10 changed files with 243 additions and 220 deletions

View File

@ -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 {

2
buildSrc/build.gradle Normal file
View File

@ -0,0 +1,2 @@
// TODO: port stuff to convention plugins

View File

@ -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")

67
buildSrc/platforms.gradle Normal file
View File

@ -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')
}

View File

@ -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'
}
}

View File

@ -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')) }
}
}
}

View File

@ -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}"

View File

@ -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')

View File

@ -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'

View File

@ -1,5 +1,6 @@
org.gradle.jvmargs = -Xmx3G
org.gradle.daemon = false
fabric.loom.multiProjectOptimisation=true
# Mod metadata
mod_id = flywheel