Skip to content

Remove dependency annotations from shaded classes - #4445

Merged
andimarek merged 6 commits into
masterfrom
remove-shaded-annotations
Aug 20, 2026
Merged

Remove dependency annotations from shaded classes#4445
andimarek merged 6 commits into
masterfrom
remove-shaded-annotations

Conversation

@andimarek

@andimarek andimarek commented Aug 19, 2026

Copy link
Copy Markdown
Member

Summary

  • define an explicit list of unbundled CLASS-retention annotations to remove from shaded class files
  • add an ASM-powered cleanup stage after shadowing and before final JAR assembly
  • preserve invisible annotations whose annotation classes are bundled, including GraphQL Java and relocated dependency annotations
  • reject new RuntimeInvisibleAnnotations and RuntimeInvisibleParameterAnnotations whose annotation classes are not bundled and are not in the removal list
  • share the class-file rewrite machinery with the existing JaCoCo annotation task
  • compile a Java 11 consumer with class-file warnings treated as errors
  • make the annotation-cleaned JAR the sole unclassified binary artifact and the sole main artifact used by consumers, signing, and publication

Artifact pipeline

The regular jar and shadowJar outputs are internal inputs to the cleanup pipeline. They now have explicit plain and shadow classifiers and live under build/intermediates, outside build/libs.

buildFinalJar is the only task that writes the unclassified binary JAR to build/libs. It consumes the annotation-cleaned class tree directly, so Gradle tracks the actual final archive instead of a temporary archive that is renamed in doLast.

The Java API and runtime variants both expose buildFinalJar. The Shadow Java variant and assemble hook are disabled, and shadowRuntimeElements is non-consumable, so dependency resolution cannot select the uncleaned intermediate. Direct signing, Maven Local publication, and remote publication all depend on verification of the final JAR.

This separation matters because multiple tasks previously owned the same output path. A direct shadowJar invocation could overwrite the cleaned JAR while Gradle still considered the cleanup/reassembly tasks up to date. Unique intermediate paths plus a single final producer remove that failure mode.

Verification

  • ./gradlew outgoingVariants: API and runtime variants expose only buildFinalJar; no consumable Shadow variant remains
  • ./gradlew clean test assemble verifyShadedClassAnnotations compileShadedJarConsumer: passed, including 5,737 tests
  • ./gradlew check -x test -x testng: passed
  • isolated publishGraphqlJavaPublicationToMavenLocal: published only the main, sources, Javadoc, and POM artifacts
  • the isolated Maven-local main JAR had the same SHA-256 as the buildFinalJar output
  • direct ./gradlew jar shadowJar invocation left the final JAR SHA-256 unchanged

The cleanup currently removes 1,345 annotations from 330 shaded class files.

Artifact size

Both artifacts were built through their complete publication pipelines with the same fixed 999.0.0-size-test release version.

Artifact Size
origin/master before removal 3,878,053 bytes
This PR after removal 3,873,126 bytes
Reduction 4,927 bytes (0.127%)

The uncompressed JAR contents decrease by 16,152 bytes. Both archives contain 2,394 entries, and their manifests are identical.

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Test Report

Test Results

Java Version Total Passed Failed Errors Skipped
Java 11 5927 (±0) 5871 (±0) 0 (±0) 0 (±0) 56 (±0)
Java 17 5927 (±0) 5870 (±0) 0 (±0) 0 (±0) 57 (±0)
Java 21 5927 (±0) 5870 (±0) 0 (±0) 0 (±0) 57 (±0)
Java 25 5927 (±0) 5870 (±0) 0 (±0) 0 (±0) 57 (±0)
jcstress 32 (±0) 32 (±0) 0 (±0) 0 (±0) 0 (±0)
Total 23740 (±0) 23513 (±0) 0 (±0) 0 (±0) 227 (±0)

Code Coverage (Java 25)

Metric Covered Missed Coverage vs Master
Lines 30047 3121 90.6% ±0.0%
Branches 8785 1519 85.3% ±0.0%
Methods 8026 1206 86.9% ±0.0%

No per-class coverage changes detected.

Full HTML report: build artifact jacoco-html-report

Updated: 2026-08-19 23:39:18 UTC

@bbakerman

Copy link
Copy Markdown
Member

I am glad AI can read it - I cant

@bbakerman bbakerman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not - hope it works

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