From ea8ee4c21a1e8a4136fac46713744cdb2427a32e Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Sun, 5 Sep 2021 19:55:42 +0300 Subject: [PATCH] Add option to disable deprecated POM generation and the warnings together with it (#487) --- .../fabricmc/loom/api/LoomGradleExtensionAPI.java | 12 ++++++++++++ .../loom/configuration/MavenPublication.java | 9 ++++++++- .../loom/extension/LoomGradleExtensionApiImpl.java | 6 ++++++ .../loom/extension/MinecraftGradleExtension.java | 7 +++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java b/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java index 4fb8bae..26ecb3b 100644 --- a/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java +++ b/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java @@ -34,6 +34,7 @@ import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.file.RegularFileProperty; import org.gradle.api.provider.ListProperty; import org.gradle.api.provider.Property; +import org.gradle.api.publish.maven.MavenPublication; import org.jetbrains.annotations.ApiStatus; import net.fabricmc.loom.api.decompilers.LoomDecompiler; @@ -184,4 +185,15 @@ public interface LoomGradleExtensionAPI { * @return the property controlling the setup of remapped variants */ Property getSetupRemappedVariants(); + + /** + * Disables the deprecated POM generation for a publication. + * This is useful if you want to suppress deprecation warnings when you're not using software components. + * + *

Experimental API: Will be removed in Loom 0.12 together with the deprecated POM generation functionality. + * + * @param publication the maven publication + */ + @ApiStatus.Experimental + void disableDeprecatedPomGeneration(MavenPublication publication); } diff --git a/src/main/java/net/fabricmc/loom/configuration/MavenPublication.java b/src/main/java/net/fabricmc/loom/configuration/MavenPublication.java index 5578201..682f6ad 100644 --- a/src/main/java/net/fabricmc/loom/configuration/MavenPublication.java +++ b/src/main/java/net/fabricmc/loom/configuration/MavenPublication.java @@ -25,10 +25,12 @@ package net.fabricmc.loom.configuration; import java.lang.reflect.Method; +import java.util.Collections; import java.util.HashSet; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.WeakHashMap; import java.util.concurrent.atomic.AtomicBoolean; import groovy.util.Node; @@ -49,6 +51,7 @@ public final class MavenPublication { JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, "compile", JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, "runtime" ); + private static final Set EXCLUDED_PUBLICATIONS = Collections.newSetFromMap(new WeakHashMap<>()); private MavenPublication() { } @@ -88,7 +91,7 @@ public final class MavenPublication { continue; } - if (hasSoftwareComponent(publication)) { + if (hasSoftwareComponent(publication) || EXCLUDED_PUBLICATIONS.contains(publication)) { continue; } else if (!reportedDeprecation.get()) { var deprecationHelper = LoomGradleExtension.get(project).getDeprecationHelper(); @@ -142,4 +145,8 @@ public final class MavenPublication { } }); } + + public static void excludePublication(Publication publication) { + EXCLUDED_PUBLICATIONS.add(publication); + } } diff --git a/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java b/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java index 9b2edbf..610808f 100644 --- a/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java +++ b/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java @@ -32,6 +32,7 @@ import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.file.RegularFileProperty; import org.gradle.api.provider.ListProperty; import org.gradle.api.provider.Property; +import org.gradle.api.publish.maven.MavenPublication; import net.fabricmc.loom.api.LoomGradleExtensionAPI; import net.fabricmc.loom.api.MixinApExtensionAPI; @@ -152,6 +153,11 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA protected abstract LoomFiles getFiles(); + @Override + public void disableDeprecatedPomGeneration(MavenPublication publication) { + net.fabricmc.loom.configuration.MavenPublication.excludePublication(publication); + } + // This is here to ensure that LoomGradleExtensionApiImpl compiles without any unimplemented methods private final class EnsureCompile extends LoomGradleExtensionApiImpl { private EnsureCompile() { diff --git a/src/main/java/net/fabricmc/loom/extension/MinecraftGradleExtension.java b/src/main/java/net/fabricmc/loom/extension/MinecraftGradleExtension.java index c93c010..4da6011 100644 --- a/src/main/java/net/fabricmc/loom/extension/MinecraftGradleExtension.java +++ b/src/main/java/net/fabricmc/loom/extension/MinecraftGradleExtension.java @@ -31,6 +31,7 @@ import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.file.RegularFileProperty; import org.gradle.api.provider.ListProperty; import org.gradle.api.provider.Property; +import org.gradle.api.publish.maven.MavenPublication; import net.fabricmc.loom.api.LoomGradleExtensionAPI; import net.fabricmc.loom.api.MixinApExtensionAPI; @@ -137,4 +138,10 @@ public class MinecraftGradleExtension implements LoomGradleExtensionAPI { reportDeprecation(); return parent.getSetupRemappedVariants(); } + + @Override + public void disableDeprecatedPomGeneration(MavenPublication publication) { + reportDeprecation(); + parent.disableDeprecatedPomGeneration(publication); + } }