From 95277bb9b173c300b6ccc8c27293ee609ebc019e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 00:50:27 +0800 Subject: [PATCH 1/7] Update plugin com.gradle.develocity to v3.19 (#1104) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 69acce744..774c947d5 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,7 +15,7 @@ pluginManagement { } plugins { - id("com.gradle.develocity") version "3.18.2" + id("com.gradle.develocity") version "3.19" } develocity { From 099865d50d78e25efe3937bf26d050ecadd891ba Mon Sep 17 00:00:00 2001 From: Zongle Wang Date: Thu, 12 Dec 2024 22:34:16 -0500 Subject: [PATCH 2/7] Compat deprecated getDependencyProject usage (#1106) --- .../gradle/plugins/shadow/internal/GradleCompat.kt | 13 +++++++++++++ .../gradle/plugins/shadow/internal/UnusedTracker.kt | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/GradleCompat.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/GradleCompat.kt index a4a3b5dae..cf60ff126 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/GradleCompat.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/GradleCompat.kt @@ -2,6 +2,7 @@ package com.github.jengelman.gradle.plugins.shadow.internal import org.gradle.api.Project import org.gradle.api.artifacts.Configuration +import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.model.ObjectFactory import org.gradle.api.plugins.JavaPlugin @@ -34,3 +35,15 @@ internal fun ConfigurableFileCollection.conventionCompat(vararg paths: Any): Con this } } + +/** + * TODO: this could be removed after bumping the min Gradle requirement to 8.11 or above. + */ +internal fun ProjectDependency.dependencyProjectCompat(project: Project): Project { + return if (GradleVersion.current() >= GradleVersion.version("8.11")) { + project.project(path) + } else { + @Suppress("DEPRECATION") + dependencyProject + } +} diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/UnusedTracker.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/UnusedTracker.kt index 78a02537a..436bfcea1 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/UnusedTracker.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/UnusedTracker.kt @@ -56,7 +56,7 @@ internal class UnusedTracker private constructor( apiDependencies.forEach { dep -> when (dep) { is ProjectDependency -> { - apiJars.addAll(getApiJarsFromProject(dep.dependencyProject)) + apiJars.addAll(getApiJarsFromProject(dep.dependencyProjectCompat(project))) addJar(runtimeConfiguration, dep, apiJars) } is SelfResolvingDependency -> { From 9c6f79450a3b31e83bf82ff85e6c793b8454244f Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 13 Dec 2024 10:59:35 +0800 Subject: [PATCH 3/7] Use zip for includedDependencies --- .../github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b31bcc10c..9ce5f6c34 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 @@ -128,7 +128,7 @@ public abstract class ShadowJar : @get:Classpath public open val includedDependencies: ConfigurableFileCollection = objectFactory.fileCollection() - .conventionCompat(dependencyFilter.map { it.resolve(configurations.get()) }) + .conventionCompat(dependencyFilter.zip(configurations) { df, cs -> df.resolve(cs) }) /** * Enable relocation of packages in the jar. From 37ffdb7148e8c4d99d3b824896633c646e399b30 Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 13 Dec 2024 11:16:30 +0800 Subject: [PATCH 4/7] Tweak toMinimize, apiJars, and sourceSetsClassesDirs --- .../gradle/plugins/shadow/tasks/ShadowJar.kt | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) 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 9ce5f6c34..cf5e24fda 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 @@ -10,7 +10,6 @@ import com.github.jengelman.gradle.plugins.shadow.internal.UnusedTracker import com.github.jengelman.gradle.plugins.shadow.internal.ZipCompressor import com.github.jengelman.gradle.plugins.shadow.internal.conventionCompat import com.github.jengelman.gradle.plugins.shadow.internal.property -import com.github.jengelman.gradle.plugins.shadow.internal.unsafeLazy import com.github.jengelman.gradle.plugins.shadow.relocation.CacheableRelocator import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator import com.github.jengelman.gradle.plugins.shadow.relocation.SimpleRelocator @@ -20,6 +19,7 @@ import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionMo import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer.Companion.create +import java.io.File import java.util.jar.JarFile import org.apache.tools.zip.ZipOutputStream import org.gradle.api.Action @@ -53,6 +53,7 @@ public abstract class ShadowJar : Jar(), ShadowSpec { private val dependencyFilterForMinimize = MinimizeDependencyFilter(project) + private inline val sourceSets get() = project.extensions.getByType(SourceSetContainer::class.java) init { // shadow filters out files later. This was the default behavior in Gradle < 6.x @@ -68,35 +69,38 @@ public abstract class ShadowJar : @get:Internal override val stats: ShadowStats = ShadowStats() + /** + * Minimize the jar by removing unused classes. + * + * Defaults to `false`. + */ + @get:Input + public open val minimizeJar: Property = objectFactory.property(false) + @get:Classpath - public open val toMinimize: ConfigurableFileCollection by unsafeLazy { - objectFactory.fileCollection().apply { - if (minimizeJar.get()) { - conventionCompat(dependencyFilterForMinimize.resolve(configurations.get()) - apiJars) - } - } - } + public open val toMinimize: ConfigurableFileCollection = objectFactory.fileCollection() + .conventionCompat( + minimizeJar.map { + if (it) (dependencyFilterForMinimize.resolve(configurations.get()) - apiJars) else emptySet() + }, + ) @get:Classpath - public open val apiJars: ConfigurableFileCollection by unsafeLazy { - objectFactory.fileCollection().apply { - if (minimizeJar.get()) { - conventionCompat(UnusedTracker.getApiJarsFromProject(project)) - } - } - } + public open val apiJars: ConfigurableFileCollection = objectFactory.fileCollection() + .conventionCompat( + minimizeJar.map { + if (it) UnusedTracker.getApiJarsFromProject(project) else emptySet() + }, + ) @get:InputFiles @get:PathSensitive(PathSensitivity.RELATIVE) - public open val sourceSetsClassesDirs: ConfigurableFileCollection by unsafeLazy { - objectFactory.fileCollection().apply { - if (minimizeJar.get()) { - project.extensions.getByType(SourceSetContainer::class.java).forEach { sourceSet -> - from(sourceSet.output.classesDirs.filter { it.isDirectory }) - } - } - } - } + public open val sourceSetsClassesDirs: ConfigurableFileCollection = objectFactory.fileCollection() + .conventionCompat( + minimizeJar.map { + if (it) sourceSets.map { sourceSet -> sourceSet.output.classesDirs.filter(File::isDirectory) } else emptySet() + }, + ) @get:Internal protected open val rootPatternSet: PatternSet @@ -146,14 +150,6 @@ public abstract class ShadowJar : @get:Input public open val relocationPrefix: Property = objectFactory.property(ShadowBasePlugin.SHADOW) - /** - * Minimize the jar by removing unused classes. - * - * Defaults to `false`. - */ - @get:Input - public open val minimizeJar: Property = objectFactory.property(false) - @Internal override fun getManifest(): InheritManifest = super.manifest as InheritManifest From c748c2a6dc35bb2740e0083273ca81742915594b Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 13 Dec 2024 11:40:51 +0800 Subject: [PATCH 5/7] Remove unsafeLazy --- .../github/jengelman/gradle/plugins/shadow/internal/Utils.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/Utils.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/Utils.kt index 4ec58607b..daac5eae8 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/Utils.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/Utils.kt @@ -26,11 +26,6 @@ internal fun createDefaultFileTreeElement( return DefaultFileTreeElement(file, relativePath, chmod, stat) } -@Suppress("NOTHING_TO_INLINE") -internal inline fun unsafeLazy(noinline initializer: () -> T): Lazy { - return lazy(LazyThreadSafetyMode.NONE, initializer) -} - internal fun Properties.inputStream( charset: Charset = Charsets.ISO_8859_1, comments: String = "", From 75f5647a7e2be9a33c3e65c44c19c8e9123421a7 Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 13 Dec 2024 21:09:32 +0800 Subject: [PATCH 6/7] Add fileCollection extension --- .../plugins/shadow/internal/GradleCompat.kt | 14 +++--- .../gradle/plugins/shadow/tasks/ShadowJar.kt | 44 ++++++++++--------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/GradleCompat.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/GradleCompat.kt index cf60ff126..9bf7fd7df 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/GradleCompat.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/GradleCompat.kt @@ -27,12 +27,14 @@ internal inline fun ObjectFactory.property(defaultValue: T? = /** * TODO: this could be removed after bumping the min Gradle requirement to 8.8 or above. */ -internal fun ConfigurableFileCollection.conventionCompat(vararg paths: Any): ConfigurableFileCollection { - return if (GradleVersion.current() >= GradleVersion.version("8.8")) { - convention(paths) - } else { - setFrom(paths) - this +internal inline fun ObjectFactory.fileCollection(path: () -> Any): ConfigurableFileCollection { + return fileCollection().apply { + @Suppress("UnstableApiUsage") + if (GradleVersion.current() >= GradleVersion.version("8.8")) { + convention(path()) + } else { + setFrom(path()) + } } } 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 cf5e24fda..109f5a3cc 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 @@ -8,7 +8,7 @@ import com.github.jengelman.gradle.plugins.shadow.internal.DependencyFilter import com.github.jengelman.gradle.plugins.shadow.internal.MinimizeDependencyFilter import com.github.jengelman.gradle.plugins.shadow.internal.UnusedTracker import com.github.jengelman.gradle.plugins.shadow.internal.ZipCompressor -import com.github.jengelman.gradle.plugins.shadow.internal.conventionCompat +import com.github.jengelman.gradle.plugins.shadow.internal.fileCollection import com.github.jengelman.gradle.plugins.shadow.internal.property import com.github.jengelman.gradle.plugins.shadow.relocation.CacheableRelocator import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator @@ -78,29 +78,30 @@ public abstract class ShadowJar : public open val minimizeJar: Property = objectFactory.property(false) @get:Classpath - public open val toMinimize: ConfigurableFileCollection = objectFactory.fileCollection() - .conventionCompat( - minimizeJar.map { - if (it) (dependencyFilterForMinimize.resolve(configurations.get()) - apiJars) else emptySet() - }, - ) + public open val toMinimize: ConfigurableFileCollection = objectFactory.fileCollection { + minimizeJar.map { + if (it) (dependencyFilterForMinimize.resolve(configurations.get()) - apiJars) else emptySet() + } + } @get:Classpath - public open val apiJars: ConfigurableFileCollection = objectFactory.fileCollection() - .conventionCompat( - minimizeJar.map { - if (it) UnusedTracker.getApiJarsFromProject(project) else emptySet() - }, - ) + public open val apiJars: ConfigurableFileCollection = objectFactory.fileCollection { + minimizeJar.map { minimize -> + if (minimize) UnusedTracker.getApiJarsFromProject(project) else emptySet() + } + } @get:InputFiles @get:PathSensitive(PathSensitivity.RELATIVE) - public open val sourceSetsClassesDirs: ConfigurableFileCollection = objectFactory.fileCollection() - .conventionCompat( - minimizeJar.map { - if (it) sourceSets.map { sourceSet -> sourceSet.output.classesDirs.filter(File::isDirectory) } else emptySet() - }, - ) + public open val sourceSetsClassesDirs: ConfigurableFileCollection = objectFactory.fileCollection { + minimizeJar.map { minimize -> + if (minimize) { + sourceSets.map { sourceSet -> sourceSet.output.classesDirs.filter(File::isDirectory) } + } else { + emptySet() + } + } + } @get:Internal protected open val rootPatternSet: PatternSet @@ -131,8 +132,9 @@ public abstract class ShadowJar : objectFactory.property(DefaultDependencyFilter(project)) @get:Classpath - public open val includedDependencies: ConfigurableFileCollection = objectFactory.fileCollection() - .conventionCompat(dependencyFilter.zip(configurations) { df, cs -> df.resolve(cs) }) + public open val includedDependencies: ConfigurableFileCollection = objectFactory.fileCollection { + dependencyFilter.zip(configurations) { df, cs -> df.resolve(cs) } + } /** * Enable relocation of packages in the jar. From 8a9eab128e0abcd9825543efeb24721e287a8f0b Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 13 Dec 2024 21:12:07 +0800 Subject: [PATCH 7/7] Cleanup --- .../jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 109f5a3cc..d93f6ea89 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 @@ -86,16 +86,16 @@ public abstract class ShadowJar : @get:Classpath public open val apiJars: ConfigurableFileCollection = objectFactory.fileCollection { - minimizeJar.map { minimize -> - if (minimize) UnusedTracker.getApiJarsFromProject(project) else emptySet() + minimizeJar.map { + if (it) UnusedTracker.getApiJarsFromProject(project) else emptySet() } } @get:InputFiles @get:PathSensitive(PathSensitivity.RELATIVE) public open val sourceSetsClassesDirs: ConfigurableFileCollection = objectFactory.fileCollection { - minimizeJar.map { minimize -> - if (minimize) { + minimizeJar.map { + if (it) { sourceSets.map { sourceSet -> sourceSet.output.classesDirs.filter(File::isDirectory) } } else { emptySet()