Skip to content

Simplify apiJars/toMinimize/sourceSetsClassesDirs initializations - #2276

Closed
Goooler wants to merge 1 commit into
mainfrom
g/20260903/simplify-props
Closed

Simplify apiJars/toMinimize/sourceSetsClassesDirs initializations#2276
Goooler wants to merge 1 commit into
mainfrom
g/20260903/simplify-props

Conversation

@Goooler

@Goooler Goooler commented Sep 3, 2026

Copy link
Copy Markdown
Member

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 configurations property earlier and refactor toMinimize, apiJars, and sourceSetsClassesDirs initialization.
  • Add Project.sourceSetsOrNull extension 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

  • sourceSetsClassesDirs is 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 unless minimizeJar was 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

  • apiJars is also a @Classpath input. Making it unconditional means getApiJars() (which may create and later resolve the shadowMinimizeApi configuration) 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.

Comment on lines 127 to 130
@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 }
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! #2277.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants