Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public interface LoomGradleExtensionAPI {

RegularFileProperty getAccessWidenerPath();

RegularFileProperty getFabricModJsonPath();

NamedDomainObjectContainer<DecompilerOptions> getDecompilerOptions();

void decompilers(Action<NamedDomainObjectContainer<DecompilerOptions>> action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
protected final ListProperty<JarProcessor> jarProcessors;
protected final ConfigurableFileCollection log4jConfigs;
protected final RegularFileProperty accessWidener;
protected final RegularFileProperty fabricModJsonPath;
protected final ManifestLocations versionsManifests;
protected final Property<String> customMetadata;
protected final SetProperty<String> knownIndyBsms;
Expand Down Expand Up @@ -118,6 +119,7 @@ protected LoomGradleExtensionApiImpl(Project project, LoomFiles directories) {
.empty();
this.log4jConfigs = project.files(directories.getDefaultLog4jConfigFile());
this.accessWidener = project.getObjects().fileProperty();
this.fabricModJsonPath = project.getObjects().fileProperty();
this.versionsManifests = new ManifestLocations();
this.versionsManifests.add("mojang", MirrorUtil.getVersionManifests(project), -2);
this.versionsManifests.add("fabric_experimental", MirrorUtil.getExperimentalVersions(project), -1);
Expand Down Expand Up @@ -205,6 +207,11 @@ public RegularFileProperty getAccessWidenerPath() {
return accessWidener;
}

@Override
public RegularFileProperty getFabricModJsonPath() {
return fabricModJsonPath;
}

@Override
public NamedDomainObjectContainer<DecompilerOptions> getDecompilerOptions() {
return decompilers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@

import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import net.fabricmc.loom.api.LoomGradleExtensionAPI;
import org.gradle.api.Project;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.SourceSet;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;
Expand Down Expand Up @@ -109,7 +111,10 @@ public static Optional<FabricModJson> createFromZipOptional(Path zipPath) {

@Nullable
public static FabricModJson createFromSourceSetsNullable(Project project, SourceSet... sourceSets) throws IOException {
final File file = SourceSetHelper.findFirstFileInResource(FABRIC_MOD_JSON, project, sourceSets);
final RegularFileProperty fmjPath = project.getExtensions().getByType(LoomGradleExtensionAPI.class).getFabricModJsonPath();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this right place to do this, FabricModJsonHelpers.getModsInProject is the place for it.

Copy link
Author

@kikugie kikugie Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly? My implementation was based on the fact that the createFromSourceSetsNullable method is called from the Loom and Fabric API extensions (LoomGradleExtensionApiImpl.getModVersion and FabricApiAbstractSourceSet.configureSourceSet), so using the property here would provide the desired file to those too.

final File file = fmjPath.isPresent()
? fmjPath.getAsFile().get()
: SourceSetHelper.findFirstFileInResource(FABRIC_MOD_JSON, project, sourceSets);

if (file == null) {
return null;
Expand Down