Repository: GradleUp/shadow
Pull request #1103 (2024-12-12 10:21:50)

Migrate all `ListProperty` usages to `SetProperty`
---

- [x] [CHANGELOG](https://github.com/GradleUp/shadow/blob/main/src/docs/changes/README.md)'s "Unreleased" section has been updated, if applicable.



Patch:
diff --git a/api/shadow.api b/api/shadow.api
index c73a61e1..e9bb98b2 100644
--- a/api/shadow.api
+++ b/api/shadow.api
@@ -83,7 +83,7 @@ public class com/github/jengelman/gradle/plugins/shadow/ShadowStats {
 }
 
 public class com/github/jengelman/gradle/plugins/shadow/impl/RelocatorRemapper : org/objectweb/asm/commons/Remapper {
-	public fun <init> (Ljava/util/List;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;)V
+	public fun <init> (Ljava/util/Set;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;)V
 	public fun hasRelocators ()Z
 	public fun map (Ljava/lang/String;)Ljava/lang/String;
 	public fun mapPath (Lcom/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction$RelativeArchivePath;)Ljava/lang/String;
@@ -245,7 +245,7 @@ public final class com/github/jengelman/gradle/plugins/shadow/tasks/KnowsTask$Co
 
 public class com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction : org/gradle/api/internal/file/copy/CopyAction {
 	public static final field Companion Lcom/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction$Companion;
-	public fun <init> (Ljava/io/File;Lcom/github/jengelman/gradle/plugins/shadow/internal/ZipCompressor;Lorg/gradle/api/internal/DocumentationRegistry;Ljava/lang/String;Ljava/util/List;Ljava/util/List;Lorg/gradle/api/tasks/util/PatternSet;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;ZZ)V
+	public fun <init> (Ljava/io/File;Lcom/github/jengelman/gradle/plugins/shadow/internal/ZipCompressor;Lorg/gradle/api/internal/DocumentationRegistry;Ljava/lang/String;Ljava/util/Set;Ljava/util/Set;Lorg/gradle/api/tasks/util/PatternSet;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;ZZ)V
 	public fun execute (Lorg/gradle/api/internal/file/copy/CopyActionProcessingStream;)Lorg/gradle/api/tasks/WorkResult;
 }
 
@@ -302,7 +302,7 @@ public abstract class com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar
 	public fun dependencies (Lorg/gradle/api/Action;)Lcom/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar;
 	public synthetic fun dependencies (Lorg/gradle/api/Action;)Lcom/github/jengelman/gradle/plugins/shadow/tasks/ShadowSpec;
 	public fun getApiJars ()Lorg/gradle/api/file/ConfigurableFileCollection;
-	public fun getConfigurations ()Lorg/gradle/api/provider/ListProperty;
+	public fun getConfigurations ()Lorg/gradle/api/provider/SetProperty;
 	public fun getDependencyFilter ()Lorg/gradle/api/provider/Property;
 	public fun getEnableRelocation ()Lorg/gradle/api/provider/Property;
 	public fun getIncludedDependencies ()Lorg/gradle/api/file/ConfigurableFileCollection;
@@ -311,12 +311,12 @@ public abstract class com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar
 	public synthetic fun getManifest ()Lorg/gradle/api/java/archives/Manifest;
 	public fun getMinimizeJar ()Lorg/gradle/api/provider/Property;
 	public fun getRelocationPrefix ()Lorg/gradle/api/provider/Property;
-	public fun getRelocators ()Lorg/gradle/api/provider/ListProperty;
+	public fun getRelocators ()Lorg/gradle/api/provider/SetProperty;
 	protected fun getRootPatternSet ()Lorg/gradle/api/tasks/util/PatternSet;
 	public fun getSourceSetsClassesDirs ()Lorg/gradle/api/file/ConfigurableFileCollection;
 	public fun getStats ()Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;
 	public fun getToMinimize ()Lorg/gradle/api/file/ConfigurableFileCollection;
-	public fun getTransformers ()Lorg/gradle/api/provider/ListProperty;
+	public fun getTransformers ()Lorg/gradle/api/provider/SetProperty;
 	public fun mergeGroovyExtensionModules ()Lcom/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar;
 	public synthetic fun mergeGroovyExtensionModules ()Lcom/github/jengelman/gradle/plugins/shadow/tasks/ShadowSpec;
 	public fun mergeServiceFiles ()Lcom/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar;
@@ -465,7 +465,7 @@ public class com/github/jengelman/gradle/plugins/shadow/transformers/ManifestApp
 	public fun <init> (Lorg/gradle/api/model/ObjectFactory;)V
 	public fun append (Ljava/lang/String;Ljava/lang/Comparable;)Lcom/github/jengelman/gradle/plugins/shadow/transformers/ManifestAppenderTransformer;
 	public fun canTransformResource (Lorg/gradle/api/file/FileTreeElement;)Z
-	public fun getAttributes ()Lorg/gradle/api/provider/ListProperty;
+	public fun getAttributes ()Lorg/gradle/api/provider/SetProperty;
 	public final fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
 	public fun hasTransformedResource ()Z
 	public fun modifyOutputStream (Lorg/apache/tools/zip/ZipOutputStream;Z)V
@@ -501,7 +501,7 @@ public class com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesF
 	public fun getMergeSeparator ()Lorg/gradle/api/provider/Property;
 	public fun getMergeStrategy ()Lorg/gradle/api/provider/Property;
 	public final fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
-	public fun getPaths ()Lorg/gradle/api/provider/ListProperty;
+	public fun getPaths ()Lorg/gradle/api/provider/SetProperty;
 	public fun hasTransformedResource ()Z
 	public fun modifyOutputStream (Lorg/apache/tools/zip/ZipOutputStream;Z)V
 	public fun transform (Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;)V
@@ -574,21 +574,21 @@ public final class com/github/jengelman/gradle/plugins/shadow/transformers/Trans
 public final class com/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext {
 	public static final field Companion Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext$Companion;
 	public fun <init> (Ljava/lang/String;Ljava/io/InputStream;)V
-	public fun <init> (Ljava/lang/String;Ljava/io/InputStream;Ljava/util/List;)V
-	public fun <init> (Ljava/lang/String;Ljava/io/InputStream;Ljava/util/List;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;)V
-	public synthetic fun <init> (Ljava/lang/String;Ljava/io/InputStream;Ljava/util/List;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
+	public fun <init> (Ljava/lang/String;Ljava/io/InputStream;Ljava/util/Set;)V
+	public fun <init> (Ljava/lang/String;Ljava/io/InputStream;Ljava/util/Set;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;)V
+	public synthetic fun <init> (Ljava/lang/String;Ljava/io/InputStream;Ljava/util/Set;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
 	public static final fun builder ()Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext$Builder;
 	public final fun component1 ()Ljava/lang/String;
 	public final fun component2 ()Ljava/io/InputStream;
-	public final fun component3 ()Ljava/util/List;
+	public final fun component3 ()Ljava/util/Set;
 	public final fun component4 ()Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;
-	public final fun copy (Ljava/lang/String;Ljava/io/InputStream;Ljava/util/List;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;)Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;
-	public static synthetic fun copy$default (Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;Ljava/lang/String;Ljava/io/InputStream;Ljava/util/List;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;ILjava/lang/Object;)Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;
+	public final fun copy (Ljava/lang/String;Ljava/io/InputStream;Ljava/util/Set;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;)Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;
+	public static synthetic fun copy$default (Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;Ljava/lang/String;Ljava/io/InputStream;Ljava/util/Set;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;ILjava/lang/Object;)Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;
 	public fun equals (Ljava/lang/Object;)Z
 	public static final fun getEntryTimestamp (ZJ)J
 	public final fun getInputStream ()Ljava/io/InputStream;
 	public final fun getPath ()Ljava/lang/String;
-	public final fun getRelocators ()Ljava/util/List;
+	public final fun getRelocators ()Ljava/util/Set;
 	public final fun getStats ()Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;
 	public fun hashCode ()I
 	public fun toString ()Ljava/lang/String;
@@ -599,7 +599,7 @@ public final class com/github/jengelman/gradle/plugins/shadow/transformers/Trans
 	public final fun build ()Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;
 	public final fun inputStream (Ljava/io/InputStream;)Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext$Builder;
 	public final fun path (Ljava/lang/String;)Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext$Builder;
-	public final fun relocators (Ljava/util/List;)Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext$Builder;
+	public final fun relocators (Ljava/util/Set;)Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext$Builder;
 	public final fun stats (Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;)Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext$Builder;
 }
 
diff --git a/src/docs/changes/README.md b/src/docs/changes/README.md
index 63dc6b7f..96e83d9d 100644
--- a/src/docs/changes/README.md
+++ b/src/docs/changes/README.md
@@ -7,6 +7,11 @@
 
 - Sync `SimpleRelocator` changes from maven-shade-plugin. ([#1076](https://github.com/GradleUp/shadow/pull/1076))
 
+**Changed**
+
+- **BREAKING CHANGE:** Migrate all `ListProperty` usages to `SetProperty`. ([#1103](https://github.com/GradleUp/shadow/pull/1103))  
+  Some public `List` parameters are also changed to `Set`.
+
 
 ## [v9.0.0-beta4] (2024-12-06)
 
diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/impl/RelocatorRemapper.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/impl/RelocatorRemapper.kt
index 92ddede2..9337a364 100644
--- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/impl/RelocatorRemapper.kt
+++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/impl/RelocatorRemapper.kt
@@ -15,7 +15,7 @@ import org.objectweb.asm.commons.Remapper
  * @author John Engelman
  */
 public open class RelocatorRemapper(
-  private val relocators: List<Relocator>,
+  private val relocators: Set<Relocator>,
   private val stats: ShadowStats,
 ) : Remapper() {
   private val classPattern: Pattern = Pattern.compile("(\\[*)?L(.+)")
diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.kt
index 657b1ab1..b16de7ec 100644
--- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.kt
+++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.kt
@@ -44,8 +44,8 @@ public open class ShadowCopyAction internal constructor(
   private val compressor: ZipCompressor,
   private val documentationRegistry: DocumentationRegistry,
   private val encoding: String?,
-  private val transformers: List<Transformer>,
-  private val relocators: List<Relocator>,
+  private val transformers: Set<Transformer>,
+  private val relocators: Set<Relocator>,
   private val patternSet: PatternSet,
   private val stats: ShadowStats,
   private val preserveFileTimestamps: Boolean,
@@ -58,8 +58,8 @@ public open class ShadowCopyAction internal constructor(
     compressor: ZipCompressor,
     documentationRegistry: DocumentationRegistry,
     encoding: String?,
-    transformers: List<Transformer>,
-    relocators: List<Relocator>,
+    transformers: Set<Transformer>,
+    relocators: Set<Relocator>,
     patternSet: PatternSet,
     stats: ShadowStats,
     preserveFileTimestamps: Boolean,
@@ -166,8 +166,8 @@ public open class ShadowCopyAction internal constructor(
   private inner class StreamAction(
     private val zipOutStr: ZipOutputStream,
     encoding: String?,
-    private val transformers: List<Transformer>,
-    private val relocators: List<Relocator>,
+    private val transformers: Set<Transformer>,
+    private val relocators: Set<Relocator>,
     private val patternSet: PatternSet,
     private val unused: Set<String>,
     private val stats: ShadowStats,
diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt
index 8640650a..b31bcc10 100644
--- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt
+++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt
@@ -31,8 +31,8 @@ import org.gradle.api.internal.DocumentationRegistry
 import org.gradle.api.internal.file.FileResolver
 import org.gradle.api.internal.file.copy.CopyAction
 import org.gradle.api.internal.file.copy.DefaultCopySpec
-import org.gradle.api.provider.ListProperty
 import org.gradle.api.provider.Property
+import org.gradle.api.provider.SetProperty
 import org.gradle.api.tasks.CacheableTask
 import org.gradle.api.tasks.Classpath
 import org.gradle.api.tasks.Input
@@ -113,14 +113,14 @@ public abstract class ShadowJar :
     }
 
   @get:Nested
-  public open val transformers: ListProperty<Transformer> = objectFactory.listProperty(Transformer::class.java)
+  public open val transformers: SetProperty<Transformer> = objectFactory.setProperty(Transformer::class.java)
 
   @get:Nested
-  public open val relocators: ListProperty<Relocator> = objectFactory.listProperty(Relocator::class.java)
+  public open val relocators: SetProperty<Relocator> = objectFactory.setProperty(Relocator::class.java)
 
   @get:Classpath
   @get:Optional
-  public open val configurations: ListProperty<Configuration> = objectFactory.listProperty(Configuration::class.java)
+  public open val configurations: SetProperty<Configuration> = objectFactory.setProperty(Configuration::class.java)
 
   @get:Internal
   public open val dependencyFilter: Property<DependencyFilter> =
@@ -294,8 +294,8 @@ public abstract class ShadowJar :
       if (!enableRelocation.get()) return emptyList()
 
       val prefix = relocationPrefix.get()
-      // Must cast configurations to List<FileCollection> to fix type mismatch in runtime.
-      return (configurations.get() as List<FileCollection>).flatMap { configuration ->
+      // Must cast configurations to Set<FileCollection> to fix type mismatch in runtime.
+      return (configurations.get() as Set<FileCollection>).flatMap { configuration ->
         configuration.files.flatMap { file ->
           JarFile(file).use { jarFile ->
             jarFile.entries().toList()
diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestAppenderTransformer.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestAppenderTransformer.kt
index 473c8156..230058cf 100644
--- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestAppenderTransformer.kt
+++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestAppenderTransformer.kt
@@ -8,7 +8,7 @@ import org.apache.tools.zip.ZipEntry
 import org.apache.tools.zip.ZipOutputStream
 import org.gradle.api.file.FileTreeElement
 import org.gradle.api.model.ObjectFactory
-import org.gradle.api.provider.ListProperty
+import org.gradle.api.provider.SetProperty
 import org.gradle.api.tasks.Input
 import org.slf4j.LoggerFactory
 
@@ -27,8 +27,8 @@ public open class ManifestAppenderTransformer @Inject constructor(
 
   @Suppress("UNCHECKED_CAST")
   @get:Input
-  public open val attributes: ListProperty<Pair<String, Comparable<*>>> =
-    objectFactory.listProperty(Pair::class.java) as ListProperty<Pair<String, Comparable<*>>>
+  public open val attributes: SetProperty<Pair<String, Comparable<*>>> =
+    objectFactory.setProperty(Pair::class.java) as SetProperty<Pair<String, Comparable<*>>>
 
   override fun canTransformResource(element: FileTreeElement): Boolean {
     return MANIFEST_NAME.equals(element.relativePath.pathString, ignoreCase = true)
diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer.kt
index 1e3a80a5..57be7a40 100644
--- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer.kt
+++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer.kt
@@ -14,9 +14,9 @@ import org.apache.tools.zip.ZipEntry
 import org.apache.tools.zip.ZipOutputStream
 import org.gradle.api.file.FileTreeElement
 import org.gradle.api.model.ObjectFactory
-import org.gradle.api.provider.ListProperty
 import org.gradle.api.provider.MapProperty
 import org.gradle.api.provider.Property
+import org.gradle.api.provider.SetProperty
 import org.gradle.api.tasks.Input
 import org.gradle.api.tasks.Internal
 
@@ -107,7 +107,7 @@ public open class PropertiesFileTransformer @Inject constructor(
   internal val propertiesEntries = mutableMapOf<String, CleanProperties>()
 
   @get:Input
-  public open val paths: ListProperty<String> = objectFactory.listProperty(String::class.java)
+  public open val paths: SetProperty<String> = objectFactory.setProperty(String::class.java)
 
   @Suppress("UNCHECKED_CAST")
   @get:Input
diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext.kt
index 3bb9b135..cefd226a 100644
--- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext.kt
+++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext.kt
@@ -8,18 +8,18 @@ import java.io.InputStream
 public data class TransformerContext @JvmOverloads constructor(
   val path: String,
   val inputStream: InputStream,
-  val relocators: List<Relocator> = emptyList(),
+  val relocators: Set<Relocator> = emptySet(),
   val stats: ShadowStats = ShadowStats(),
 ) {
   public class Builder {
     private var path = ""
     private var inputStream: InputStream? = null
-    private var relocators = emptyList<Relocator>()
+    private var relocators = emptySet<Relocator>()
     private var stats = ShadowStats()
 
     public fun path(path: String): Builder = apply { this.path = path }
     public fun inputStream(inputStream: InputStream): Builder = apply { this.inputStream = inputStream }
-    public fun relocators(relocators: List<Relocator>): Builder = apply { this.relocators = relocators }
+    public fun relocators(relocators: Set<Relocator>): Builder = apply { this.relocators = relocators }
     public fun stats(stats: ShadowStats): Builder = apply { this.stats = stats }
     public fun build(): TransformerContext = TransformerContext(
       path = path,


Test patch:
diff --git a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/Log4j2PluginsCacheFileTransformerTest.kt b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/Log4j2PluginsCacheFileTransformerTest.kt
index 1b933940..f411b33a 100644
--- a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/Log4j2PluginsCacheFileTransformerTest.kt
+++ b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/Log4j2PluginsCacheFileTransformerTest.kt
@@ -47,7 +47,7 @@ class Log4j2PluginsCacheFileTransformerTest : BaseTransformerTest<Log4j2PluginsC
   }
 
   private fun context(vararg relocator: SimpleRelocator): TransformerContext {
-    return TransformerContext(PLUGIN_CACHE_FILE, requireResourceAsStream(PLUGIN_CACHE_FILE), relocator.toList())
+    return TransformerContext(PLUGIN_CACHE_FILE, requireResourceAsStream(PLUGIN_CACHE_FILE), relocator.toSet())
   }
 
   private companion object {