Gradle grumbles

- Apply java, maven-publish to all projects
- Prefer the tasks.named() syntax for configuring tasks
- Separate shared configuration for platform projects into a separate
  configure block
- Add more fields to processResources
- Make helper methods static
- Exclude duplicated package infos
This commit is contained in:
Jozufozu 2024-04-20 18:28:54 -07:00
parent 57ac1b08f4
commit 8d4fe7722c
8 changed files with 173 additions and 121 deletions

View File

@ -8,6 +8,12 @@ plugins {
println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
subprojects {
apply plugin: "dev.architectury.loom"
base {
archivesName = "flywheel-${name}-${artifact_minecraft_version}"
}
boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equalsIgnoreCase('false');
ext.buildNumber = System.getenv('BUILD_NUMBER')
@ -15,63 +21,10 @@ subprojects {
group = 'com.jozufozu.flywheel'
version = mod_version + (dev && buildNumber != null ? "-${buildNumber}" : '')
apply plugin: "java"
apply plugin: "maven-publish"
apply plugin: "dev.architectury.loom"
loom {
silentMojangMappingsLicense()
}
if (it != project(':common')) {
loom {
runs {
client {
ideConfigGenerated true
property 'flw.dumpShaderSource', 'true'
property 'flw.debugMemorySafety', 'true'
programArgs '--width', '1280', '--height', '720'
}
server {
ideConfigGenerated true
programArgs '--nogui'
}
}
}
}
tasks {
// make builds reproducible
withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
// module metadata is often broken on multi-platform projects
withType(GenerateModuleMetadata).configureEach {
enabled = false
}
}
processResources.configure {
from(project(':common').sourceSets.main.resources)
var replaceProperties = [
minecraft_version : minecraft_version,
minecraft_version_range: minecraft_version_range,
forge_version : forge_version,
forge_version_range : forge_version_range,
loader_version_range : loader_version_range,
mod_version : mod_version
]
inputs.properties replaceProperties
filesMatching(['META-INF/mods.toml', 'META-INF/neoforge.mods.toml', 'pack.mcmeta', 'fabric.mod.json']) {
expand replaceProperties + [project: project]
}
}
repositories {
maven {
name = 'ParchmentMC'
@ -103,8 +56,43 @@ subprojects {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip")
})
implementation "com.google.code.findbugs:jsr305:3.0.2"
}
processResources {
var replaceProperties = [
minecraft_version : minecraft_version,
minecraft_version_range: minecraft_version_range,
forge_version : forge_version,
forge_version_range : forge_version_range,
loader_version_range : loader_version_range,
mod_version : mod_version,
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,
]
inputs.properties replaceProperties
filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml', 'META-INF/neoforge.mods.toml']) {
expand replaceProperties + [project: project]
}
}
apply from: rootProject.file('gradle/package-infos.gradle')
ideaSyncTask.finalizedBy(generatePackageInfos)
}
// Need to setup the java plugin for all projects so that our subprojects can find an output directory
allprojects {
apply plugin: "java"
apply plugin: "maven-publish"
java {
JavaVersion javaVersion = JavaVersion.toVersion(java_version)
sourceCompatibility = javaVersion
@ -116,46 +104,105 @@ subprojects {
withJavadocJar()
}
tasks.withType(JavaCompile).configureEach {
source(project(':common').sourceSets.main.allSource)
options.encoding = 'UTF-8'
options.release = Integer.parseInt(java_version)
options.compilerArgs = ['-Xdiags:verbose']
// make builds reproducible
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
jar.configure {
// 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 = ''
addManifest(it)
addLicense(it)
addManifest(jar)
addLicense(jar)
}
sourcesJar.configure {
from(project(':common').sourceSets.main.allSource)
addManifest(it)
addLicense(it)
tasks.named('sourcesJar', Jar).configure { Jar jar ->
addManifest(jar)
addLicense(jar)
}
javadoc.configure {
source(project(':common').sourceSets.main.allJava)
tasks.named('javadoc', Javadoc).configure { Javadoc javadoc ->
javadoc.source sourceSets.main.allJava
// prevent java 8's strict doclint for javadocs from failing builds
options.addStringOption('Xdoclint:none', '-quiet')
javadoc.options.addStringOption('Xdoclint:none', '-quiet')
}
apply from: rootProject.file('gradle/package-infos.gradle')
ideaSyncTask.finalizedBy(generatePackageInfos)
}
void addLicense(jarTask) {
// Common configuration for platform dependent subprojects.
for (final def 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'
}
}
void addManifest(jarTask) {
static void addManifest(Jar jarTask) {
jarTask.manifest {
attributes([
'Specification-Title' : 'flywheel',
@ -169,6 +216,21 @@ void addManifest(jarTask) {
}
}
// 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 {

View File

@ -1,12 +1,6 @@
base {
archivesName = "flywheel-${project.name}-${artifact_minecraft_version}"
}
dependencies {
modCompileOnly "net.fabricmc:fabric-loader:$fabric_loader_version"
compileOnly "com.google.code.findbugs:jsr305:3.0.2"
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
}

View File

@ -1,6 +1,6 @@
{
"pack": {
"description": "Flywheel resources",
"description": "${mod_name} resources",
"pack_format": 15
}
}

View File

@ -1,9 +1,3 @@
evaluationDependsOn(':common')
base {
archivesName = "flywheel-${project.name}-${artifact_minecraft_version}"
}
dependencies {
modCompileOnly "net.fabricmc:fabric-loader:$fabric_loader_version"
modLocalRuntime "net.fabricmc:fabric-loader:$fabric_loader_version"
@ -18,8 +12,6 @@ dependencies {
modCompileOnly "maven.modrinth:sodium:$sodium_version"
modCompileOnly "maven.modrinth:iris:$iris_version"
compileOnly "com.google.code.findbugs:jsr305:3.0.2"
}
publishing {

View File

@ -1,19 +1,20 @@
{
"schemaVersion": 1,
"id": "flywheel",
"version": "${version}",
"name": "Flywheel",
"description": "A modern engine for modded minecraft.",
"id": "${mod_id}",
"version": "${mod_version}",
"name": "${mod_name}",
"description": "${mod_description}",
"authors": [
"Jozufozu",
"PepperCode1"
],
"contact": {
"homepage": "https://fabricmc.net/",
"sources": "https://github.com/FabricMC/fabric-example-mod"
"homepage": "${mod_homepage}",
"sources": "${mod_sources}",
"issues": "${mod_issues}"
},
"license": "MIT",
"icon": "assets/flywheel/logo.png",
"license": "${mod_license}",
"icon": "logo.png",
"environment": "*",
"entrypoints": {
"client": [
@ -27,6 +28,6 @@
],
"depends": {
"fabric": "*",
"minecraft": ">=1.20.1"
"minecraft": "${minecraft_version_range}"
}
}

View File

@ -1,9 +1,4 @@
evaluationDependsOn(':common')
base {
archivesName = "flywheel-${project.name}-${artifact_minecraft_version}"
}
// Add some forge specific configurations
loom {
forge {
mixinConfig "flywheel.backend.mixins.json"
@ -26,8 +21,6 @@ dependencies {
modCompileOnly "maven.modrinth:embeddium:$embeddium_version"
modCompileOnly "maven.modrinth:oculus:$oculus_version"
compileOnly "com.google.code.findbugs:jsr305:3.0.2"
}
publishing {

View File

@ -1,33 +1,32 @@
modLoader = "javafml"
loaderVersion = "${loader_version_range}"
issueTrackerURL = "https://github.com/Jozufozu/Flywheel/issues"
license = "MIT"
issueTrackerURL = "${mod_issues}"
license = "${mod_license}"
[[mods]]
modId = "flywheel"
modId = "${mod_id}"
version = "${mod_version}"
displayName = "Flywheel"
displayName = "${mod_name}"
logoFile = "logo.png"
displayURL = "https://github.com/Jozufozu/Flywheel"
displayURL = "${mod_homepage}"
authors = "Jozufozu, PepperCode1"
description = '''
A modern engine for modded minecraft.'''
description = "${mod_description}"
[[dependencies.flywheel]]
[[dependencies.${mod_id}]]
modId = "forge"
mandatory = true
versionRange = "${forge_version_range}"
ordering = "NONE"
side = "CLIENT"
[[dependencies.flywheel]]
[[dependencies.${mod_id}]]
modId = "minecraft"
mandatory = true
versionRange = "${minecraft_version_range}"
ordering = "NONE"
side = "CLIENT"
[[dependencies.flywheel]]
[[dependencies.${mod_id}]]
modId = "rubidium"
# This replicates a "breaks" dependency.
# There's a mixin crash with Rubidium <0.7.0.

View File

@ -1,19 +1,30 @@
org.gradle.jvmargs = -Xmx3G
org.gradle.daemon = false
# mod version info
# General mod metadata
mod_id = flywheel
mod_name = Flywheel
mod_license = MIT
mod_description = An overhauled entity and block entity rendering API.
mod_sources = https://github.com/Jozufozu/Flywheel
mod_issues = https://github.com/Jozufozu/Flywheel/issues
mod_homepage = https://github.com/Jozufozu/Flywheel
# Mod version info
mod_version = 1.0.0-alpha
artifact_minecraft_version = 1.20.1
minecraft_version = 1.20.1
forge_version = 47.2.19
fabric_loader_version = 0.15.9
fabric_api_version = 0.92.1+1.20.1
# Version ranges for the mods.toml
minecraft_version_range = [1.20.1,1.20.2)
forge_version_range = [47,)
loader_version_range = [47,)
# build dependency versions
# Build dependency versions
java_version = 17
arch_loom_version = 1.6-SNAPSHOT
forgegradle_version = [6.0.16,6.2)