|
16 | 16 | import org.gradle.api.Project; |
17 | 17 | import org.gradle.api.artifacts.ModuleDependency; |
18 | 18 | import org.gradle.api.plugins.JavaLibraryPlugin; |
| 19 | +import org.jetbrains.annotations.Nullable; |
19 | 20 | import org.slf4j.Logger; |
20 | 21 | import org.slf4j.LoggerFactory; |
21 | 22 |
|
@@ -87,9 +88,10 @@ public void enable( |
87 | 88 | versionCapabilities) |
88 | 89 | : ModdingDependencies.createVanillaOnly(neoForm, neoFormNotation); |
89 | 90 |
|
90 | | - if (neoForgeVersion != null) { |
91 | | - populateNeoForgeRepositoryFilter(project, neoForgeVersion); |
92 | | - } |
| 91 | + // Always apply at least the stable baseline filter to the NeoForged |
| 92 | + // repository. When a NeoForge version is selected we also discover |
| 93 | + // additional game-library modules from its metadata. |
| 94 | + populateNeoForgeRepositoryFilter(project, neoForgeVersion); |
93 | 95 |
|
94 | 96 | ArtifactNamingStrategy artifactNamingStrategy; |
95 | 97 | // It's helpful to be able to differentiate the Vanilla jar and the NeoForge jar in classic multiloader setups. |
@@ -129,28 +131,29 @@ public void enable( |
129 | 131 | * The HTTP download bypasses Gradle's dependency resolution so the repository content |
130 | 132 | * descriptor stays unlocked and can receive its first {@code content()} call. |
131 | 133 | */ |
132 | | - private static void populateNeoForgeRepositoryFilter(Project project, String neoForgeVersion) { |
133 | | - // Regex to extract group:module pairs from Gradle Module Metadata JSON. |
134 | | - var depPattern = Pattern.compile("\"group\":\\s*\"([^\"]+)\",\\s*\"module\":\\s*\"([^\"]+)\""); |
135 | | - |
136 | | - // 1. Discover game library modules from the NeoForge artifact metadata. |
137 | | - fetchModuleDependencies("net/neoforged/neoforge/" + neoForgeVersion |
138 | | - + "/neoforge-" + neoForgeVersion + ".module", depPattern); |
139 | | - |
140 | | - // 2. Discover build tool modules from the NeoForm Runtime metadata. |
141 | | - // NFRT ships external tools (DiffPatch, AutoRenamingTool, etc.) whose |
142 | | - // transitive dependencies are also rehosted on the NeoForged Maven. |
143 | | - var nfrtVersion = NeoFormRuntimeExtension.getVersion(project); |
144 | | - fetchModuleDependencies("net/neoforged/neoform-runtime/" + nfrtVersion |
145 | | - + "/neoform-runtime-" + nfrtVersion + ".module", depPattern); |
146 | | - |
147 | | - // Apply the content filter now — before any dependency resolution uses the |
148 | | - // NeoForge repository. |
149 | | - try { |
150 | | - RepositoriesPlugin.applyContentFilter(project); |
151 | | - } catch (Exception e) { |
152 | | - LOG.warn("Failed to apply NeoForge repository content filter: {}", e.getMessage()); |
| 134 | + private static void populateNeoForgeRepositoryFilter(Project project, |
| 135 | + @Nullable String neoForgeVersion) { |
| 136 | + // Clear any stale dynamic modules from a previous build in this daemon. |
| 137 | + NeoForgedRepositoryFilter.clearGameLibraries(); |
| 138 | + |
| 139 | + if (neoForgeVersion != null) { |
| 140 | + var depPattern = Pattern.compile("\"group\":\\s*\"([^\"]+)\",\\s*\"module\":\\s*\"([^\"]+)\""); |
| 141 | + |
| 142 | + // Discover game library modules from the NeoForge artifact metadata. |
| 143 | + fetchModuleDependencies("net/neoforged/neoforge/" + neoForgeVersion |
| 144 | + + "/neoforge-" + neoForgeVersion + ".module", depPattern); |
| 145 | + |
| 146 | + // Discover build tool modules from the NeoForm Runtime metadata. |
| 147 | + var nfrtVersion = NeoFormRuntimeExtension.getVersion(project); |
| 148 | + fetchModuleDependencies("net/neoforged/neoform-runtime/" + nfrtVersion |
| 149 | + + "/neoform-runtime-" + nfrtVersion + ".module", depPattern); |
153 | 150 | } |
| 151 | + |
| 152 | + // Apply the content filter now — before any dependency resolution uses |
| 153 | + // the NeoForge repository. In the vanilla-only case this installs the |
| 154 | + // stable baseline; when a NeoForge version is selected it also includes |
| 155 | + // any dynamically discovered modules. |
| 156 | + RepositoriesPlugin.applyContentFilter(project); |
154 | 157 | } |
155 | 158 |
|
156 | 159 | private static void fetchModuleDependencies(String path, Pattern depPattern) { |
|
0 commit comments