Simplify apiJars/toMinimize/sourceSetsClassesDirs initializations - #2276
Simplify apiJars/toMinimize/sourceSetsClassesDirs initializations#2276Goooler wants to merge 1 commit into
apiJars/toMinimize/sourceSetsClassesDirs initializations#2276Conversation
b83580f to
69027b4
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The new unconditional task input wiring can trigger dependency resolution and broaden task inputs even when minimization is disabled, impacting performance/caching and potentially changing behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Refactors ShadowJar minimization-related input properties to simplify their initialization, and adds a nullable sourceSetsOrNull helper for safer access when the Java plugin/source sets aren’t present.
Changes:
- Move
configurationsproperty earlier and refactortoMinimize,apiJars, andsourceSetsClassesDirsinitialization. - Add
Project.sourceSetsOrNullextension for optional source set lookup.
File summaries
| File | Description |
|---|---|
| src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt | Refactors minimization-related input file collections and switches source set access to sourceSetsOrNull. |
| src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/GradleCompat.kt | Adds sourceSetsOrNull convenience accessor. |
Review details
Suppressed comments (2)
src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt:144
sourceSetsClassesDirsis declared as@InputFiles. With the new unconditional provider, the task’s inputs now include source set class directories even when minimization is disabled, which can invalidate up-to-date checks/build cache entries and adds unnecessary input snapshotting overhead. Previously this input was empty unlessminimizeJarwas enabled.
project.provider {
project.sourceSetsOrNull?.map {
it.output.classesDirs.filter(File::isDirectory)
} ?: emptySet<File>()
}
src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt:135
apiJarsis also a@Classpathinput. Making it unconditional meansgetApiJars()(which may create and later resolve theshadowMinimizeApiconfiguration) becomes part of every ShadowJar execution/input snapshot even when minimization is disabled, increasing configuration and resolution work and affecting cacheability.
@get:Classpath
public open val apiJars: ConfigurableFileCollection = objectFactory.fileCollection {
project.getApiJars()
}
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @get:Classpath | ||
| public open val toMinimize: ConfigurableFileCollection = objectFactory.fileCollection { | ||
| _minimizeJar.map { | ||
| if (it) (_minimizeSpec.resolve(configurations.get()) - apiJars) else emptySet() | ||
| } | ||
| configurations.map { _minimizeSpec.resolve(it) - apiJars } | ||
| } |
No description provided.