Skip to content

Commit

Permalink
Trying to fix multi-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeltumn committed Nov 25, 2024
1 parent 6d84c14 commit cc812c3
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ gradle-app.setting

# Common working directory
run/
runs/

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
45 changes: 45 additions & 0 deletions buildSrc/src/main/kotlin/multiloader.common.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import gradle.kotlin.dsl.accessors._38abe6feebbbb2ba8fa777a7b88e8035.jar
import gradle.kotlin.dsl.accessors._38abe6feebbbb2ba8fa777a7b88e8035.java
import org.gradle.api.tasks.bundling.AbstractArchiveTask
import org.gradle.kotlin.dsl.withType

plugins {
idea
`java-library`
`maven-publish`
}

java {
withSourcesJar()
withJavadocJar()
}

// Declare capabilities on the outgoing configurations.
// Read more about capabilities here: https://docs.gradle.org/current/userguide/component_capabilities.html#sec:declaring-additional-capabilities-for-a-local-component
setOf("apiElements", "runtimeElements", "sourcesElements", "javadocElements").forEach { variant ->
configurations.getByName(variant).outgoing {
capability("com.noxcrew:noxesium-${project.name}:$version")
capability("com.noxcrew.noxesium:noxesium:$version")
}
}

tasks {
val processResourcesTasks = listOf("processResources")

jar {
from("LICENSE") {
rename { return@rename "${it}_${rootProject.name}" }
}
}

withType<AbstractArchiveTask> {
archiveBaseName.set("noxesium-${project.name}")
}

withType<ProcessResources>().matching { processResourcesTasks.contains(it.name) }.configureEach {
inputs.property("version", project.version)
filesMatching(setOf("fabric.mod.json", "META-INF/neoforge.mods.toml")) {
expand("version" to project.version)
}
}
}
43 changes: 43 additions & 0 deletions buildSrc/src/main/kotlin/multiloader.loader.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
plugins {
id("multiloader.common")
}

configurations {
register("commonJava") {
isCanBeResolved = true
}
register("commonResources") {
isCanBeResolved = true
}
}

dependencies {
compileOnly(project(":common")) {
capabilities {
requireCapability("com.noxcrew.noxesium:noxesium")
}
}
"commonJava"(project(":common", "commonJava"))
"commonResources"(project(":common", "commonResources"))
}

tasks {
named<JavaCompile>("compileJava").configure {
dependsOn(configurations.getByName("commonJava"))
source(configurations.getByName("commonJava"))
}
named<ProcessResources>("processResources").configure {
dependsOn(configurations.getByName("commonResources"))
from(configurations.getByName("commonResources"))
}
named<Javadoc>("javadoc").configure {
dependsOn(configurations.getByName("commonJava"))
source(configurations.getByName("commonJava"))
}
named<Jar>("sourcesJar").configure {
dependsOn(configurations.getByName("commonJava"))
from(configurations.getByName("commonJava"))
dependsOn(configurations.getByName("commonResources"))
from(configurations.getByName("commonResources"))
}
}
22 changes: 22 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
plugins {
id("net.neoforged.moddev")
id("multiloader.common")
}

neoForge {
neoFormVersion.set("${property("neo_form_version")}")

// Validate AT files and raise errors when they have invalid targets
// This option is false by default, but turning it on is recommended
setAccessTransformers(file("src/main/resources/noxesium.cfg"))
validateAccessTransformers = true
}

dependencies {
Expand All @@ -17,4 +23,20 @@ dependencies {

// Use PRTree as a custom dependency
api(libs.prtree)
}

configurations {
register("commonJava") {
isCanBeResolved = false
isCanBeConsumed = true
}
register("commonResources") {
isCanBeResolved = false
isCanBeConsumed = true
}
}

artifacts {
add("commonJava", sourceSets["main"].java.sourceDirectories.singleFile)
add("commonResources", sourceSets["main"].resources.sourceDirectories.singleFile)
}
Empty file.
40 changes: 11 additions & 29 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
plugins {
id("fabric-loom")
id("multiloader.loader")
}

repositories {
maven { url = uri("https://maven.shedaniel.me/") }
}

dependencies {
// Depend on the common project
api(project(":common"))
// Depend on api and prtree
api(project(":api"))
api(libs.prtree)

// To change the versions see the gradle.properties file
minecraft("com.mojang:minecraft:${property("minecraft_version")}")
Expand All @@ -18,11 +20,6 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation("net.fabricmc.fabric-api:fabric-api:${property("fabric_version")}")

// Include dependencies in the jar
include(project(":api"))
include(project(":common"))
include(libs.prtree)

// Compatibility with other mods
if (property("enableSodium") == "true") {
modImplementation("maven.modrinth:sodium:${property("sodium")}")
Expand All @@ -32,25 +29,20 @@ dependencies {
isTransitive = false
}
}
}

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
// Include dependencies in the jar
include(project(":api"))
include(project(":common"))
include(libs.prtree)
}

loom {
accessWidenerPath.set(file("src/main/resources/noxesium.accesswidener"))
accessWidenerPath.set(project(":common").file("src/main/resources/noxesium.accesswidener"))
}

tasks {
processResources {
inputs.property("version", project.version)
filesMatching("fabric.mod.json") {
expand("version" to project.version)
}
named<ProcessResources>("processResources").configure {
exclude("noxesium.cfg")
}

withType<JavaCompile> {
Expand All @@ -64,14 +56,4 @@ tasks {
exclude("**/modmenu/**.java")
}
}

withType<AbstractArchiveTask> {
archiveBaseName.set("noxesium")
}

jar {
from("LICENSE") {
rename { return@rename "${it}_${rootProject.name}" }
}
}
}
11 changes: 11 additions & 0 deletions neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@ neoForge {

// Validate AT files and raise errors when they have invalid targets
// This option is false by default, but turning it on is recommended
setAccessTransformers(project(":common").file("src/main/resources/noxesium.cfg"))
validateAccessTransformers = true

runs {
create("client") {
client()
ideName = "NeoForge Client (:${project.name})"
gameDirectory.set(file("runs/client"))
}
}
}

tasks {
named<ProcessResources>("processResources").configure {
exclude("noxesium.accesswidener")
}
}
4 changes: 2 additions & 2 deletions neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
modLoader = "javafml"
loaderVersion = "${forge_loader_version_range}"
loaderVersion = "[4,)"
license = "LGPLv3"

[[mods]]
modId = "noxesium"
version = "${file.jarVersion}}"
version = "${version}"
displayName = "Noxesium"
authors = "Noxcrew"
logoFile = "logo.png"
Expand Down

0 comments on commit cc812c3

Please sign in to comment.