Skip to content

Commit

Permalink
More work on runs
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Dec 2, 2024
1 parent ac0acad commit 2859f59
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 67 deletions.
37 changes: 20 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ plugins {
id("me.modmuss50.mod-publish-plugin") version "0.8.1" apply false
}

/*
* Gets the version name from the latest Git tag
*/
// https://stackoverflow.com/questions/28498688/gradle-script-to-autoversion-and-include-the-commit-hash-in-android
extensions.create("runConfigCommon", RunConfigCommon.class)

def getGitCommit = providers.exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
}.standardOutput.getAsText().map { it.trim() }
Expand All @@ -21,29 +19,22 @@ def aw2at = Aw2AtTask.configureDefault(
)

neoForge {
neoFormVersion = "1.21.3-20241023.131943"
neoFormVersion = neoform_version
validateAccessTransformers = true
accessTransformers.files.setFrom(aw2at.flatMap { t -> t.getOutputFile() })
}

class FixAsmRule implements ComponentMetadataRule {
@Override
void execute(ComponentMetadataContext ctx) {
ctx.details.allVariants {
it.withDependencies {
it.removeIf {
it.group == "org.ow2.asm"
}
}
}
}
runConfigCommon {
systemProperties.put "mixin.debug", "true"
systemProperties.put "Moonrise.MaxViewDistance", "128"
}

dependencies {
// todo: check versions
compileOnly "net.fabricmc:sponge-mixin:0.15.4+mixin.0.8.7"
compileOnly "io.github.llamalad7:mixinextras-common:0.4.1"
components.withModule("net.neoforged:minecraft-dependencies", FixAsmRule.class)
// work around minecraft (MDG) forcing ASM 9.3 which is incompatible with the above deps...
components.withModule("net.neoforged:minecraft-dependencies", RemoveAsmDependency.class)

api("ca.spottedleaf:concurrentutil:${rootProject.concurrentutil_version}")
api("ca.spottedleaf:yamlconfig:${rootProject.yamlconfig_version}")
Expand Down Expand Up @@ -136,4 +127,16 @@ subprojects {
minecraftVersions = supportedMcVersions
}
}

// Setup a run with lithium for compatibility testing
configurations.create("lithium")
dependencies {
String coordinates = "maven.modrinth:lithium:"
if (getProject().name == "Moonrise-NeoForge") {
coordinates += rootProject.neo_lithium_version
} else {
coordinates += rootProject.fabric_lithium_version
}
lithium coordinates
}
}
14 changes: 14 additions & 0 deletions buildSrc/src/main/java/RemoveAsmDependency.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import java.util.Objects;
import org.gradle.api.artifacts.ComponentMetadataContext;
import org.gradle.api.artifacts.ComponentMetadataRule;

public abstract class RemoveAsmDependency implements ComponentMetadataRule {
@Override
public void execute(final ComponentMetadataContext ctx) {
ctx.getDetails().allVariants(variant -> {
variant.withDependencies(deps -> {
deps.removeIf(dep -> Objects.equals(dep.getGroup(), "org.ow2.asm"));
});
});
}
}
5 changes: 5 additions & 0 deletions buildSrc/src/main/java/RunConfigCommon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import org.gradle.api.provider.MapProperty;

public abstract class RunConfigCommon {
public abstract MapProperty<String, String> getSystemProperties();
}
41 changes: 22 additions & 19 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@ dependencies {
include fabricApiLibs.base
}

processResources {
inputs.property "version", project.version

tasks.processResources {
def properties = [
"version": project.version,
"minecraft_version": minecraft_version,
"loader_version": loader_version,
"mod_version": mod_version
]
inputs.properties(properties)
filesMatching("fabric.mod.json") {
expand "version": project.version, "minecraft_version": minecraft_version, "loader_version": loader_version, "mod_version": mod_version
expand properties
}
}

shadowJar {
tasks.shadowJar {
archiveClassifier = "dev-all"
destinationDirectory = layout.buildDirectory.dir("libs")
configurations = [project.configurations.shadow]
Expand Down Expand Up @@ -68,10 +73,8 @@ loom {
mixin {
useLegacyMixinAp = false
}
runs.all {
runs.configureEach {
ideConfigGenerated true
property "mixin.debug", "true"
property "Moonrise.MaxViewDistance", "128"
}
mods {
main {
Expand All @@ -81,27 +84,27 @@ loom {
}
}

afterEvaluate {
loom.runs.configureEach { cfg ->
runConfigCommon.systemProperties.get().each {
cfg.property it.key, it.value
}
}
}

// Setup a run with lithium for compatibility testing
sourceSets.create("lithium")
configurations.create("lithium")
loom {
createRemapConfigurations(sourceSets.lithium)
runs {
register("lithiumClient") {
client()
property "mixin.debug", "true"
}
}
}
configurations.modLithiumRuntimeOnly {
extendsFrom configurations.lithium
}
tasks.named("runLithiumClient", net.fabricmc.loom.task.RunGameTask.class) {
getClasspath().from(configurations.modRuntimeClasspathLithiumMapped)
}
dependencies {
String coordinates = "maven.modrinth:lithium:"
if (getProject().name == "Moonrise-NeoForge") {
coordinates += rootProject.neo_lithium_version
} else {
coordinates += rootProject.fabric_lithium_version
}
modLithiumRuntimeOnly coordinates
}
6 changes: 4 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G
org.gradle.daemon=false
org.gradle.parallel=true
org.gradle.caching=true
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.21.3
loader_version=0.16.9
supported_minecraft_versions=1.21.3
neoforge_version=21.3.31-beta
neoforge_version=21.3.51-beta
neoform_version=1.21.3-20241023.131943
fabric_api_version=0.107.0+1.21.3
snakeyaml_version=2.3
concurrentutil_version=0.0.2-SNAPSHOT
Expand Down
85 changes: 57 additions & 28 deletions neoforge/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import net.neoforged.moddevgradle.internal.RunGameTask
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import net.neoforged.moddevgradle.internal.RunGameTask

plugins {
id("net.neoforged.moddev")
Expand Down Expand Up @@ -30,17 +31,11 @@ neoForge {
}
}
runs {
configureEach {
additionalRuntimeClasspathConfiguration.extendsFrom configurations.libs
systemProperties.put('mixin.debug', 'true')
}
client {
client()
// loadedMods.set([]) // Work around module issues by using the production jar for dev runs
}
server {
server()
// loadedMods.set([]) // Work around module issues by using the production jar for dev runs
}
}
}
Expand All @@ -52,38 +47,29 @@ dependencies {

libs("ca.spottedleaf:concurrentutil:${rootProject.concurrentutil_version}")
libs("ca.spottedleaf:yamlconfig:${rootProject.yamlconfig_version}")
libs("org.yaml:snakeyaml:${rootProject.snakeyaml_version}")
additionalRuntimeClasspath libs("org.yaml:snakeyaml:${rootProject.snakeyaml_version}")

implementation "me.shedaniel.cloth:cloth-config-neoforge:${rootProject.cloth_version}"
jarJar "me.shedaniel.cloth:cloth-config-neoforge:${rootProject.cloth_version}"
}

// Work around module issues by using the production jar for dev runs
/*
tasks.withType(RunGameTask).configureEach {
dependsOn(tasks.shadowJar)
doFirst {
def jar = file("run/mods/main.jar")
jar.parentFile.mkdirs()
jar.delete()
Files.copy(tasks.shadowJar.archiveFile.get().asFile.toPath(), jar.toPath())
}
}
*/

processResources {
inputs.property "version", project.version

tasks.processResources {
def properties = [
"version": project.version,
"minecraft_version": minecraft_version,
"mod_version": mod_version
]
inputs.properties(properties)
filesMatching("META-INF/neoforge.mods.toml") {
expand "version": project.version, "minecraft_version": minecraft_version, "loader_version": loader_version, "mod_version": mod_version
expand properties
}
}

jar {
archiveClassifier = ""
tasks.jar {
archiveClassifier = "slim"
}

shadowJar {
tasks.shadowJar {
archiveClassifier = ""
destinationDirectory = layout.buildDirectory.dir("libs")
configurations = [project.configurations.shadow]
Expand All @@ -92,6 +78,10 @@ shadowJar {
relocate 'org.yaml.snakeyaml', 'ca.spottedleaf.moonrise.libs.org.yaml.snakeyaml'
}

tasks.assemble {
dependsOn tasks.shadowJar
}

publishMods {
file = shadowJar.archiveFile
modLoaders = ["neoforge"]
Expand All @@ -111,3 +101,42 @@ publishMods {
)
}
}

afterEvaluate {
neoForge.runs.configureEach { cfg ->
runConfigCommon.systemProperties.get().each {
cfg.systemProperties.put it.key, it.value
}
}
}

// Setup a run with lithium for compatibility testing
neoForge {
runs {
lithiumClient {
client()
disableIdeRun()
}
}
}
tasks.withType(RunGameTask).configureEach {
if (name == "runLithiumClient") {
return
}
def out = gameDirectory.get().getAsFile().toPath().resolve("mods/lithium-tmp.jar")
doFirst {
Files.deleteIfExists(out)
}
}
def lithium = configurations.lithium
tasks.runLithiumClient {
def out = gameDirectory.get().getAsFile().toPath().resolve("mods/lithium-tmp.jar")
doFirst {
for (File file in lithium) {
Files.copy(file.toPath(), out, StandardCopyOption.REPLACE_EXISTING)
}
}
doLast {
Files.deleteIfExists(out)
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pluginManagement {

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
id("quiet-fabric-loom") version "1.8.306" apply false
id("quiet-fabric-loom") version "1.8.309" apply false
id("net.neoforged.moddev") version "2.0.49-beta" apply false
id 'com.gradleup.shadow' version '8.3.5' apply false
}
Expand Down

0 comments on commit 2859f59

Please sign in to comment.