Skip to content

Never package bytecode-modified class files in published JARs#4343

Merged
andimarek merged 1 commit intomasterfrom
fix/exclude-modified-classes-from-jar
Mar 18, 2026
Merged

Never package bytecode-modified class files in published JARs#4343
andimarek merged 1 commit intomasterfrom
fix/exclude-modified-classes-from-jar

Conversation

@andimarek
Copy link
Member

Summary

  • The markGeneratedEqualsHashCode task was modifying .class files in-place in build/classes/java/main and the jar task depended on it, causing every published class with equals/hashCode to contain a spurious @Generated (Lgraphql/coverage/Generated;) annotation in the bytecode
  • Fix: copy classes to a separate build/classes-jacoco/ directory before injecting annotations, prepend that directory to the test classpath (so Jacoco CRC64 checksums match the execution data), and point jacocoTestReport at the modified copy
  • The jar/shadowJar/publish tasks now only see pristine compiler output — no bytecode modifications leak into artifacts

Test plan

  • Verified original classes in build/classes/java/main remain unmodified after running markGeneratedEqualsHashCode
  • Verified classes in build/classes-jacoco/java/main contain the @Generated annotation
  • Verified the built JAR does not contain graphql.coverage.Generated annotations
  • Verified the shadow JAR does not contain graphql.coverage.Generated annotations
  • All tests pass (./gradlew test)
  • Jacoco report generates successfully with real coverage data (non-zero counters)
  • equals/hashCode methods are properly excluded from the Jacoco coverage report

🤖 Generated with Claude Code

The markGeneratedEqualsHashCode task was modifying class files in-place
in build/classes/java/main, and the jar task depended on it, causing
the @Generated-annotated bytecode to flow into published artifacts.

Fix: copy classes to a separate build/classes-jacoco/ directory before
modifying them, prepend that directory to the test classpath (so Jacoco
CRC64 checksums match), and point jacocoTestReport at the modified copy.
The jar/shadowJar tasks now only see the pristine compiler output.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@andimarek andimarek enabled auto-merge (rebase) March 18, 2026 00:34
@andimarek andimarek merged commit e53ab1a into master Mar 18, 2026
11 checks passed
@github-actions
Copy link
Contributor

Test Report

Test Results

Java Version Total Passed Failed Errors Skipped
Java 11 5708 (±0) 5652 (±0) 0 (±0) 0 (±0) 56 (±0)
Java 17 5708 (±0) 5651 (±0) 0 (±0) 0 (±0) 57 (±0)
Java 21 5708 (±0) 5651 (±0) 0 (±0) 0 (±0) 57 (±0)
Java 25 5708 (±0) 5651 (±0) 0 (±0) 0 (±0) 57 (±0)
jcstress 32 (±0) 32 (±0) 0 (±0) 0 (±0) 0 (±0)
Total 22864 (±0) 22637 (±0) 0 (±0) 0 (±0) 227 (±0)

Code Coverage (Java 25)

Metric Covered Missed Coverage vs Master
Lines 28775 3122 90.2% ±0.0%
Branches 8354 1508 84.7% ±0.0%
Methods 7699 1223 86.3% ±0.0%

No per-class coverage changes detected.

Full HTML report: build artifact jacoco-html-report

Updated: 2026-03-18 00:42:24 UTC

@dondonz
Copy link
Member

dondonz commented Mar 18, 2026

Thanks!!!

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