Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate ShadowJar to using lazy properties #1044

Merged
merged 20 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions api/shadow.api
Original file line number Diff line number Diff line change
Expand Up @@ -294,20 +294,21 @@ public abstract class com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar
protected fun createCopyAction ()Lorg/gradle/api/internal/file/copy/CopyAction;
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 final fun getApiJars ()Lorg/gradle/api/file/FileCollection;
public final fun getConfigurations ()Ljava/util/List;
public final fun getDependencyFilter ()Lcom/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter;
public final fun getIncludedDependencies ()Lorg/gradle/api/file/FileCollection;
public final fun getApiJars ()Lorg/gradle/api/file/ConfigurableFileCollection;
public abstract fun getConfigurations ()Lorg/gradle/api/provider/ListProperty;
public abstract fun getDependencyFilter ()Lorg/gradle/api/provider/Property;
public abstract fun getEnableRelocation ()Lorg/gradle/api/provider/Property;
public abstract fun getIncludedDependencies ()Lorg/gradle/api/file/ConfigurableFileCollection;
public fun getManifest ()Lcom/github/jengelman/gradle/plugins/shadow/tasks/InheritManifest;
public synthetic fun getManifest ()Lorg/gradle/api/java/archives/Manifest;
public final fun getRelocationPrefix ()Ljava/lang/String;
public final fun getRelocators ()Ljava/util/List;
public abstract fun getMinimizeJar ()Lorg/gradle/api/provider/Property;
public abstract fun getRelocationPrefix ()Lorg/gradle/api/provider/Property;
public abstract fun getRelocators ()Lorg/gradle/api/provider/ListProperty;
public final fun getRootPatternSet ()Lorg/gradle/api/tasks/util/PatternSet;
public final fun getSourceSetsClassesDirs ()Lorg/gradle/api/file/FileCollection;
public final fun getSourceSetsClassesDirs ()Lorg/gradle/api/file/ConfigurableFileCollection;
public fun getStats ()Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;
public final fun getToMinimize ()Lorg/gradle/api/file/FileCollection;
public final fun getTransformers ()Ljava/util/List;
public final fun isEnableRelocation ()Z
public final fun getToMinimize ()Lorg/gradle/api/file/ConfigurableFileCollection;
public abstract fun getTransformers ()Lorg/gradle/api/provider/ListProperty;
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;
Expand All @@ -330,12 +331,6 @@ public abstract class com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar
public synthetic fun relocate (Ljava/lang/String;Ljava/lang/String;)Lcom/github/jengelman/gradle/plugins/shadow/tasks/ShadowSpec;
public fun relocate (Ljava/lang/String;Ljava/lang/String;Lorg/gradle/api/Action;)Lcom/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar;
public synthetic fun relocate (Ljava/lang/String;Ljava/lang/String;Lorg/gradle/api/Action;)Lcom/github/jengelman/gradle/plugins/shadow/tasks/ShadowSpec;
public final fun setConfigurations (Ljava/util/List;)V
public final fun setDependencyFilter (Lcom/github/jengelman/gradle/plugins/shadow/internal/DependencyFilter;)V
public final fun setEnableRelocation (Z)V
public final fun setRelocationPrefix (Ljava/lang/String;)V
public final fun setRelocators (Ljava/util/List;)V
public final fun setTransformers (Ljava/util/List;)V
public fun transform (Lcom/github/jengelman/gradle/plugins/shadow/transformers/Transformer;)Lcom/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar;
public synthetic fun transform (Lcom/github/jengelman/gradle/plugins/shadow/transformers/Transformer;)Lcom/github/jengelman/gradle/plugins/shadow/tasks/ShadowSpec;
public fun transform (Ljava/lang/Class;)Lcom/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar;
Expand Down
8 changes: 4 additions & 4 deletions lint-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt"
line="25"
line="24"
column="1"/>
</issue>

Expand All @@ -129,7 +129,7 @@
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt"
line="26"
line="25"
column="1"/>
</issue>

Expand All @@ -140,7 +140,7 @@
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt"
line="27"
line="26"
column="1"/>
</issue>

Expand All @@ -151,7 +151,7 @@
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt"
line="28"
line="27"
column="1"/>
</issue>

Expand Down
2 changes: 2 additions & 0 deletions src/docs/changes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
**Changed**

- **BREAKING CHANGE:** Rewrite this plugin in Kotlin. ([#1012](https://github.com/GradleUp/shadow/pull/1012))
- **BREAKING CHANGE:** Migrate `ShadowJar` to using lazy properties. ([#1044](https://github.com/GradleUp/shadow/pull/1044))
`isEnableRelocation` is deprecated, use `enableRelocation` instead.
- **BREAKING CHANGE:** Resolve `Configuration` directly in `DependencyFilter`. ([#1045](https://github.com/GradleUp/shadow/pull/1045))

**Removed**
Expand Down
8 changes: 4 additions & 4 deletions src/docs/configuration/relocation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ Shadow is shipped with a task that can be used to automatically configure all pa
This feature was formally shipped into a 2nd plugin (`com.github.johnrengelman.plugin-shadow`) but has been
removed for clarity reasons in version 4.0.0.

To configure automatic dependency relocation, set `enableRelocation true` and optionally specify a custom
To configure automatic dependency relocation, set `enableRelocation = true` and optionally specify a custom
`relocationPrefix` to override the default value of `"shadow"`.

```groovy
// Configure Auto Relocation
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
enableRelocation true
relocationPrefix "myapp"
enableRelocation = true
relocationPrefix = "myapp"
}
```

Expand All @@ -84,4 +84,4 @@ In versions before 8.1.0 it was necessary to configure a separate `ConfigureShad
> Configuring package auto relocation can add significant time to the shadow process as it will process all dependencies
in the configurations declared to be shadowed. By default, this is the `runtime` or `runtimeClasspath` configurations.
Be mindful that some Gradle plugins will automatically add dependencies to your class path. You may need to remove these
dependencies if you do not intend to shadow them into your library.
dependencies if you do not intend to shadow them into your library.
4 changes: 2 additions & 2 deletions src/docs/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
}

tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
enableRelocation true
enableRelocation = true
}
```

Expand All @@ -56,4 +56,4 @@ The `ConfigureShadowRelocation` task, scans the dependencies from the configurat
packages using the specified `prefix` on the associated `ShadowJar` task.

While this is useful for developing Gradle plugins, nothing about the `ConfigureShadowRelocation` task is tied to
Gradle projects. It can be used for standard Java or Groovy projects.
Gradle projects. It can be used for standard Java or Groovy projects.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.jengelman.gradle.plugins.shadow

import com.github.jengelman.gradle.plugins.shadow.internal.DefaultDependencyFilter
import com.github.jengelman.gradle.plugins.shadow.internal.runtimeConfiguration
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import javax.inject.Inject
import org.gradle.api.Plugin
Expand Down Expand Up @@ -88,11 +90,13 @@ public abstract class ShadowJavaPlugin @Inject constructor(
shadow.manifest.attributes["Class-Path"] = attrs.joinToString(" ").trim()
}
}
shadow.from(sourceSets.getByName("main").output)
shadow.configurations = listOf(
project.configurations.findByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME)
?: project.configurations.getByName("runtime"),
)
shadow.from(sourceSets.named("main").map { it.output })
shadow.enableRelocation.convention(false)
shadow.minimizeJar.convention(false)
shadow.relocationPrefix.convention(ShadowBasePlugin.SHADOW)
shadow.dependencyFilter.convention(DefaultDependencyFilter(project))
shadow.configurations.convention(listOf(project.runtimeConfiguration))
shadow.includedDependencies.setFrom(shadow.dependencyFilter.map { it.resolve(shadow.configurations.get()) })
shadow.exclude(
"META-INF/INDEX.LIST",
"META-INF/*.SF",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import org.gradle.api.specs.Spec
import org.gradle.api.specs.Specs

internal sealed class AbstractDependencyFilter(
private val project: Project,
@Transient private val project: Project,
@Transient protected val includeSpecs: MutableList<Spec<ResolvedDependency>> = mutableListOf(),
@Transient protected val excludeSpecs: MutableList<Spec<ResolvedDependency>> = mutableListOf(),
) : DependencyFilter {
protected val includeSpecs: MutableList<Spec<ResolvedDependency>> = mutableListOf()
protected val excludeSpecs: MutableList<Spec<ResolvedDependency>> = mutableListOf()

protected abstract fun resolve(
dependencies: Set<ResolvedDependency>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ internal class UnusedTracker private constructor(
fun getApiJarsFromProject(project: Project): FileCollection {
val apiDependencies = project.configurations.findByName("api")?.dependencies
?: return project.files()
val runtimeConfiguration = project.configurations.findByName("runtimeClasspath")
?: project.configurations.getByName("runtime")
val runtimeConfiguration = project.runtimeConfiguration
val apiJars = mutableListOf<File>()
apiDependencies.forEach { dep ->
when (dep) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
package com.github.jengelman.gradle.plugins.shadow.internal

import java.io.InputStream
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.plugins.JavaPlugin

/**
* Return `runtimeClasspath` or `runtime` configuration.
*/
internal inline val Project.runtimeConfiguration: Configuration get() {
return configurations.findByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME)
?: configurations.getByName("runtime")
}

@Suppress("NOTHING_TO_INLINE")
internal inline fun <T> unsafeLazy(noinline initializer: () -> T): Lazy<T> =
lazy(LazyThreadSafetyMode.NONE, initializer)

internal fun Class<*>.requireResourceAsText(name: String): String {
return requireResourceAsStream(name).bufferedReader().readText()
Expand Down
Loading