From f1bc512eca68b604a830b811175746195eb7523f Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Wed, 26 Jan 2022 14:15:44 +0000 Subject: [PATCH] Handle no sourcesElements configuration. --- .../fabricmc/loom/task/RemapTaskConfiguration.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/task/RemapTaskConfiguration.java b/src/main/java/net/fabricmc/loom/task/RemapTaskConfiguration.java index d1cfc0f..1f6a8d1 100644 --- a/src/main/java/net/fabricmc/loom/task/RemapTaskConfiguration.java +++ b/src/main/java/net/fabricmc/loom/task/RemapTaskConfiguration.java @@ -125,11 +125,16 @@ public class RemapTaskConfiguration { task.getInputFile().convention(sourcesJarTask.getArchiveFile()); if (extension.getSetupRemappedVariants().get()) { - project.getArtifacts().add(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME, task); + if (project.getConfigurations().getNames().contains(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME)) { + project.getArtifacts().add(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME, task); - // Remove the dev sources artifact - Configuration configuration = project.getConfigurations().getByName(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME); - configuration.getArtifacts().removeIf(a -> a.getFile().equals(sourcesJarTask.getArchiveFile().get().getAsFile())); + // Remove the dev sources artifact + Configuration configuration = project.getConfigurations().getByName(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME); + configuration.getArtifacts().removeIf(a -> a.getFile().equals(sourcesJarTask.getArchiveFile().get().getAsFile())); + } else { + // Sources jar may not have been created with withSourcesJar + project.getLogger().warn("Not publishing sources jar as it was not found. Use java.withSourcesJar() to fix."); + } } });