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 to lazy properties #1036

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
21 changes: 8 additions & 13 deletions api/shadow.api
Original file line number Diff line number Diff line change
Expand Up @@ -293,19 +293,20 @@ 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 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 abstract fun getConfigurations ()Lorg/gradle/api/provider/ListProperty;
public abstract fun getDependencyFilter ()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 final 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 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 abstract fun getTransformers ()Lorg/gradle/api/provider/ListProperty;
public final fun isEnableRelocation ()Lorg/gradle/api/provider/Property;
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 @@ -328,12 +329,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
66 changes: 0 additions & 66 deletions lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,50 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="6" by="lint 8.7.2" type="baseline" client="gradle" dependencies="false" name="AGP (8.7.2)" variant="all" version="8.7.2">

<issue
id="SimpleDateFormat"
message="To get local formatting use `getDateInstance()`, `getDateTimeInstance()`, or `getTimeInstance()`, or use `new SimpleDateFormat(String template, Locale locale)` with for example `Locale.US` for ASCII dates."
errorLine1=" val year = SimpleDateFormat(&quot;yyyy&quot;).format(Date()).let {"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformer.kt"
line="75"
column="18"/>
</issue>

<issue
id="EagerGradleConfiguration"
message="Avoid using method get"
errorLine1=" project.file(&quot;${install.get().destinationDir.path}/lib/${shadowJar.get().archiveFile.get().asFile.name}&quot;)"
errorLine2=" ~~~">
<location
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.kt"
line="54"
column="35"/>
</issue>

<issue
id="EagerGradleConfiguration"
message="Avoid using method get"
errorLine1=" project.file(&quot;${install.get().destinationDir.path}/lib/${shadowJar.get().archiveFile.get().asFile.name}&quot;)"
errorLine2=" ~~~">
<location
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.kt"
line="54"
column="78"/>
</issue>

<issue
id="EagerGradleConfiguration"
message="Avoid using method get"
errorLine1=" shadow.manifest.inheritFrom(jarTask.get().manifest)"
errorLine2=" ~~~">
<location
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.kt"
line="81"
column="43"/>
</issue>

<issue
id="InternalGradleApiUsage"
message="Avoid using internal Gradle APIs"
Expand Down Expand Up @@ -210,26 +166,4 @@
column="1"/>
</issue>

<issue
id="WithTypeWithoutConfigureEach"
message="Avoid passing a closure to withType, use withType().configureEach instead"
errorLine1=" plugins.withType(JavaPlugin::class.java) {"
errorLine2=" ~~~~~~~~">
<location
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPlugin.kt"
line="14"
column="15"/>
</issue>

<issue
id="WithTypeWithoutConfigureEach"
message="Avoid passing a closure to withType, use withType().configureEach instead"
errorLine1=" plugins.withType(ApplicationPlugin::class.java) {"
errorLine2=" ~~~~~~~~">
<location
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPlugin.kt"
line="17"
column="15"/>
</issue>

</issues>
6 changes: 3 additions & 3 deletions src/docs/configuration/relocation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ To configure automatic dependency relocation, set `enableRelocation true` and op
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
enableRelocation true
relocationPrefix "myapp"
isEnableRelocation = 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
isEnableRelocation = 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
Expand Up @@ -50,8 +50,8 @@ public abstract class ShadowApplicationPlugin : Plugin<Project> {
it.group = ApplicationPlugin.APPLICATION_GROUP
it.conventionMapping.map("jvmArgs") { javaApplication.applicationDefaultJvmArgs }
it.jarFile.fileProvider(
project.providers.provider {
project.file("${install.get().destinationDir.path}/lib/${shadowJar.get().archiveFile.get().asFile.name}")
install.zip(shadowJar) { i, s ->
project.file("${i.destinationDir.path}/lib/${s.archiveFile.get().asFile.name}")
},
)
val toolchain = project.extensions.getByType(JavaPluginExtension::class.java).toolchain
Expand All @@ -70,7 +70,7 @@ public abstract class ShadowApplicationPlugin : Plugin<Project> {
it.description = "Creates OS specific scripts to run the project as a JVM application using the shadow jar"
it.group = ApplicationPlugin.APPLICATION_GROUP
it.classpath = project.files(shadowJar)
it.conventionMapping.map("mainClassName") { javaApplication.mainClass.get() }
it.mainClass.set(javaApplication.mainClass)
it.conventionMapping.map("applicationName") { javaApplication.applicationName }
it.conventionMapping.map("outputDir") { project.layout.buildDirectory.dir("scriptsShadow").get().asFile }
it.conventionMapping.map("defaultJvmOpts") { javaApplication.applicationDefaultJvmArgs }
Expand Down Expand Up @@ -98,9 +98,11 @@ public abstract class ShadowApplicationPlugin : Plugin<Project> {
}
}
task.doLast {
task.eachFile {
if (it.path == "bin/${applicationName.get()}") {
it.mode = 0x755
task.eachFile { details ->
if (details.path == "bin/${applicationName.get()}") {
details.permissions {
it.unix(755)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.jengelman.gradle.plugins.shadow

import com.github.jengelman.gradle.plugins.shadow.internal.DefaultDependencyFilter
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import javax.inject.Inject
import org.gradle.api.Plugin
Expand Down Expand Up @@ -78,6 +79,7 @@ public abstract class ShadowJavaPlugin @Inject constructor(
shadow.group = ShadowBasePlugin.GROUP_NAME
shadow.description = "Create a combined JAR of project and runtime dependencies"
shadow.archiveClassifier.set("all")
@Suppress("EagerGradleConfiguration")
shadow.manifest.inheritFrom(jarTask.get().manifest)
val attrProvider = jarTask.map { it.manifest.attributes["Class-Path"]?.toString().orEmpty() }
val files = project.objects.fileCollection().from(shadowConfiguration)
Expand All @@ -88,9 +90,17 @@ public abstract class ShadowJavaPlugin @Inject constructor(
}
}
shadow.from(sourceSets.getByName("main").output)
shadow.configurations = listOf(
project.configurations.findByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME)
?: project.configurations.getByName("runtime"),
shadow.minimizeJar.convention(false)
shadow.transformers.convention(emptyList())
shadow.relocators.convention(emptyList())
shadow.dependencyFilter.convention(DefaultDependencyFilter(project))
shadow.configurations.convention(emptyList())
shadow.includedDependencies.setFrom(shadow.dependencyFilter.map { it.resolve(shadow.configurations.get()) })
shadow.configurations.convention(
listOf(
project.configurations.findByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME)
?: project.configurations.getByName("runtime"),
),
)
shadow.exclude(
"META-INF/INDEX.LIST",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ public abstract class ShadowPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.run {
plugins.apply(ShadowBasePlugin::class.java)
@Suppress("WithTypeWithoutConfigureEach")
plugins.withType(JavaPlugin::class.java) {
plugins.apply(ShadowJavaPlugin::class.java)
}
@Suppress("WithTypeWithoutConfigureEach")
plugins.withType(ApplicationPlugin::class.java) {
plugins.apply(ShadowApplicationPlugin::class.java)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.vafer.jdependency.ClazzpathUnit
internal class UnusedTracker private constructor(
classDirs: Iterable<File>,
classJars: FileCollection,
private val _toMinimize: FileCollection,
@get:InputFiles val toMinimize: FileCollection,
) {
private val projectUnits: List<ClazzpathUnit>
private val cp = Clazzpath()
Expand All @@ -24,9 +24,6 @@ internal class UnusedTracker private constructor(
projectUnits = classDirs.map { cp.addClazzpathUnit(it) } + classJars.map { cp.addClazzpathUnit(it) }
}

@get:InputFiles
val toMinimize: FileCollection get() = _toMinimize

fun findUnused(): Set<String> {
val unused = cp.clazzes.toMutableSet()
for (cpu in projectUnits) {
Expand All @@ -37,7 +34,7 @@ internal class UnusedTracker private constructor(
}

fun addDependency(jarOrDir: File) {
if (_toMinimize.contains(jarOrDir)) {
if (toMinimize.contains(jarOrDir)) {
cp.addClazzpathUnit(jarOrDir)
}
}
Expand Down
Loading
Loading