-
Notifications
You must be signed in to change notification settings - Fork 237
Make fabric.mod.json path configurable at configuration stage.
#1364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
1c86983
1159657
87cb7b7
4dceae8
5f92ab2
4f790ba
a932931
af18d97
23f97b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,37 +24,41 @@ | |
|
|
||
| package net.fabricmc.loom.util.fmj; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import org.gradle.api.Project; | ||
| import org.gradle.api.tasks.SourceSet; | ||
|
|
||
| import net.fabricmc.loom.LoomGradleExtension; | ||
| import net.fabricmc.loom.api.LoomGradleExtensionAPI; | ||
| import net.fabricmc.loom.util.gradle.SourceSetHelper; | ||
| import net.fabricmc.loom.LoomGradleExtension; | ||
|
|
||
| public class FabricModJsonHelpers { | ||
| // Returns a list of Mods found in the provided project's main or client sourcesets | ||
| /** | ||
| * Returns the list of mods provided by either {@link LoomGradleExtensionAPI#getFabricModJsonPath()} | ||
| * or {@code fabric.mod.json} in main or client resources. | ||
| */ | ||
| public static List<FabricModJson> getModsInProject(Project project) { | ||
| final LoomGradleExtension extension = LoomGradleExtension.get(project); | ||
| var overrideFile = extension.getFabricModJsonPath().getAsFile(); | ||
|
||
|
|
||
| if (overrideFile.isPresent()) { | ||
| return List.of(FabricModJsonFactory.createFromFile(overrideFile.get())); | ||
| } | ||
|
|
||
| var sourceSets = new ArrayList<SourceSet>(); | ||
| sourceSets.add(SourceSetHelper.getMainSourceSet(project)); | ||
|
|
||
| if (extension.areEnvironmentSourceSetsSplit()) { | ||
| sourceSets.add(SourceSetHelper.getSourceSetByName("client", project)); | ||
| } | ||
|
|
||
| try { | ||
| final FabricModJson fabricModJson = FabricModJsonFactory.createFromSourceSetsNullable(project, sourceSets.toArray(SourceSet[]::new)); | ||
| final FabricModJson fabricModJson = FabricModJsonFactory.createFromSourceSetsNullable(project, sourceSets.toArray(SourceSet[]::new)); | ||
|
|
||
| if (fabricModJson != null) { | ||
| return List.of(fabricModJson); | ||
| } | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException(e); | ||
| if (fabricModJson != null) { | ||
| return List.of(fabricModJson); | ||
| } | ||
|
|
||
| return Collections.emptyList(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * This file is part of fabric-loom, licensed under the MIT License (MIT). | ||
| * | ||
| * Copyright (c) 2025 FabricMC | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
|
|
||
| package net.fabricmc.loom.test.integration | ||
|
|
||
| import org.gradle.testkit.runner.BuildResult | ||
| import spock.lang.Specification | ||
| import spock.lang.Unroll | ||
|
|
||
| import net.fabricmc.loom.test.util.GradleProjectTestTrait | ||
|
|
||
| import static org.gradle.testkit.runner.TaskOutcome.SUCCESS | ||
|
|
||
| class FabricModJsonPathTest extends Specification implements GradleProjectTestTrait { | ||
| @Unroll | ||
| def "Resolve custom FMJ"() { | ||
| setup: | ||
| GradleProject gradle = gradleProject(project: "fmjPathConfig") | ||
|
|
||
| when: | ||
| BuildResult result = gradle.run(task: "build", args: ["-PoverrideFMJ=true"]) | ||
|
|
||
| then: | ||
| result.task(":build").outcome == SUCCESS | ||
| } | ||
|
|
||
| @Unroll | ||
| def "Fail to find FMJ"() { | ||
| setup: | ||
| GradleProject gradle = gradleProject(project: "fmjPathConfig") | ||
|
|
||
| when: | ||
| BuildResult result = gradle.run(task: "build", expectFailure: true) | ||
|
|
||
| then: | ||
| result.task(":build") == null | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // This is used by a range of tests that append to this file before running the gradle tasks. | ||
| // Can be used for tests that require minimal custom setup | ||
| plugins { | ||
| id 'fabric-loom' | ||
| id 'maven-publish' | ||
| } | ||
|
|
||
| version = "1.0.0" | ||
| group = "com.example" | ||
|
|
||
| // In multi-version setup this would be a separate project, | ||
| // but a source set will suffice for a test. | ||
| sourceSets { | ||
| custom { | ||
| } | ||
| main { | ||
| compileClasspath += sourceSets.custom.compileClasspath | ||
| runtimeClasspath += sourceSets.custom.runtimeClasspath | ||
| } | ||
| } | ||
|
|
||
|
|
||
| dependencies { | ||
| minecraft "com.mojang:minecraft:1.17.1" | ||
| mappings "net.fabricmc:yarn:1.17.1+build.59:v2" | ||
| modImplementation "net.fabricmc:fabric-loader:0.11.6" | ||
| } | ||
|
|
||
| base { | ||
| archivesName = "fabric-example-mod" | ||
| } | ||
|
|
||
| if (project.hasProperty("overrideFMJ")) { | ||
| loom { | ||
| fabricModJsonPath = file("src/custom/resources/fabric.mod.json") | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "schemaVersion": 1, | ||
| "id": "testmod", | ||
| "version": "1", | ||
| "name": "Test Mod", | ||
| "custom": { | ||
| "loom:injected_interfaces": { | ||
| "net/minecraft/class_310": ["InjectedInterface"] | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.