Skip to content

Add target JVM version attribute lazily without afterEvaluate - #2358

Closed
Goooler wants to merge 1 commit into
mainfrom
g/20261107/lazy-target-jvm-attribute
Closed

Goooler wants to merge 1 commit into
mainfrom
g/20261107/lazy-target-jvm-attribute

Conversation

@Goooler

@Goooler Goooler commented Nov 7, 2026

Copy link
Copy Markdown
Member

Use attributeProvider for org.gradle.jvm.version of shadowRuntimeElements so the JVM version is not read eagerly (#2086) and the configuration is not mutated after it may have been locked by other plugins (#2054).

attributeProvider must always provide a value, so the attribute is always added now: setting addTargetJvmVersionAttribute to false or calling java.disableAutoTargetJvm() makes it fall back to java.targetCompatibility.


  • CHANGELOG's "Unreleased" section has been updated, if applicable.

Use `attributeProvider` for `org.gradle.jvm.version` of `shadowRuntimeElements`
so the JVM version is not read eagerly (#2086) and the configuration is not
mutated after it may have been locked by other plugins (#2054).

`attributeProvider` must always provide a value, so the attribute is always
added now: setting `addTargetJvmVersionAttribute` to `false` or calling
`java.disableAutoTargetJvm()` makes it fall back to `java.targetCompatibility`.
@Goooler
Goooler requested a balanced review from Copilot November 7, 2026 07:23
@Goooler Goooler changed the title Add target JVM version attribute lazily without afterEvaluate Add target JVM version attribute lazily without afterEvaluate Nov 7, 2026

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 existing fallback tests do not cover early locking of shadowRuntimeElements, so a functional regression test is needed to catch late attribute mutation and verify published JVM-version metadata.

1 open issue
What changed in this PR

This PR makes the shadowed variant’s target JVM attribute lazy, addressing eager toolchain finalization (#2086) and late configuration mutation (#2054).

Changes:

  • Uses attributeProvider instead of afterEvaluate to supply the JVM version.
  • Always includes the attribute, falling back to java.targetCompatibility when inference is disabled or unavailable.
  • Updates publishing tests and documentation for the changed opt-out behavior.
File Description
src/​main/​kotlin/​com/​github/​jengelman/​gradle/​plugins/​shadow/​ShadowJavaPlugin.kt Registers the JVM attribute lazily and removes late mutation.
src/​main/​kotlin/​com/​github/​jengelman/​gradle/​plugins/​shadow/​ShadowExtension.kt Documents inference and fallback behavior.
src/​functionalTest/​kotlin/​com/​github/​jengelman/​gradle/​plugins/​shadow/​PublishingTest.kt Updates assertions for fallback JVM metadata.
docs/​publishing/​README.md Explains the revised attribute configuration behavior.
CHANGELOG.md Records the lifecycle fixes and potentially breaking behavior.

Review effort: Balanced

Comment on lines +92 to +94
attrs.attributeProvider(
TARGET_JVM_VERSION_ATTRIBUTE,
provider {
@Goooler Goooler closed this Nov 7, 2026
@Goooler
Goooler deleted the g/20261107/lazy-target-jvm-attribute branch November 7, 2026 07:30
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