|
25 | 25 | import org.gradle.api.artifacts.ExternalModuleDependency; |
26 | 26 | import org.gradle.api.artifacts.ExternalModuleDependencyBundle; |
27 | 27 | import org.gradle.api.artifacts.repositories.MavenArtifactRepository; |
| 28 | +import org.gradle.api.attributes.Category; |
| 29 | +import org.gradle.api.attributes.DocsType; |
28 | 30 | import org.gradle.api.file.DirectoryProperty; |
29 | 31 | import org.gradle.api.file.ProjectLayout; |
30 | 32 | import org.gradle.api.flow.FlowProviders; |
@@ -247,6 +249,33 @@ private void finish(Project project) { |
247 | 249 | if (mavenizer == null) continue; |
248 | 250 |
|
249 | 251 | syncMavenizer.configure(task -> task.dependsOn(mavenizer)); |
| 252 | + |
| 253 | + var dependency = minecraftDependency.asDependency(); |
| 254 | + if (dependency == null) continue; |
| 255 | + |
| 256 | + // See https://github.com/MinecraftForge/ForgeGradle/issues/1008#issuecomment-3623727384 |
| 257 | + // Basically, if IntelliJ can't immediately find a sources JAR next to the main jar, it tries to use this scuffed task |
| 258 | + // Intercept the configuration that the task uses and replace any dependencies we have with our own |
| 259 | + project.getConfigurations().named(name -> name.startsWith("downloadArtifact_")).configureEach(configuration -> { |
| 260 | + var itor = configuration.getDependencies().iterator(); |
| 261 | + while (itor.hasNext()) { |
| 262 | + var existing = itor.next(); |
| 263 | + if (!Objects.equals(dependency.getGroup(), existing.getGroup()) |
| 264 | + || !dependency.getName().equals(existing.getName()) |
| 265 | + || !Objects.equals(dependency.getVersion(), existing.getVersion())) |
| 266 | + continue; |
| 267 | + |
| 268 | + itor.remove(); |
| 269 | + var replacement = dependency.copy(); |
| 270 | + replacement.attributes(a -> { |
| 271 | + a.attribute(Category.CATEGORY_ATTRIBUTE, a.named(Category.class, Category.DOCUMENTATION)); |
| 272 | + a.attribute(DocsType.DOCS_TYPE_ATTRIBUTE, a.named(DocsType.class, DocsType.SOURCES)); |
| 273 | + }); |
| 274 | + configuration.withDependencies(dependencies -> |
| 275 | + dependencies.add(replacement) |
| 276 | + ); |
| 277 | + } |
| 278 | + }); |
250 | 279 | } |
251 | 280 |
|
252 | 281 | project.getPluginManager().withPlugin("eclipse", eclipsePlugin -> { |
|
0 commit comments