Skip to content

fix: shade third-party deps in codeflash-runtime JAR#1911

Merged
HeshamHM28 merged 3 commits intomainfrom
cf-shaded-runtime-jar
Mar 31, 2026
Merged

fix: shade third-party deps in codeflash-runtime JAR#1911
HeshamHM28 merged 3 commits intomainfrom
cf-shaded-runtime-jar

Conversation

@HeshamHM28
Copy link
Copy Markdown
Contributor

Problem

The codeflash-runtime-1.0.0.jar is a fat JAR that bundles 2,000+ classes from Gson, Kryo, SLF4J, JaCoCo, etc. — all unshaded (no package relocation). When codeflash adds this JAR to a project's test classpath, it causes duplicate-class conflicts with the project's own dependencies.

Real-world impact: On OpenSearch, the bundled com.google.gson.* classes collide with Hadoop's Gson dependency, triggering OpenSearch's jarHell precommit check. This caused 602 build failures and 148 functions skipped.

Fix

Relocate all third-party packages under com.codeflash.shaded.* in both build systems:

Package Shaded to
com.google.gson com.codeflash.shaded.com.google.gson
com.esotericsoftware (Kryo) com.codeflash.shaded.com.esotericsoftware
org.objenesis com.codeflash.shaded.org.objenesis
org.slf4j com.codeflash.shaded.org.slf4j
org.jacoco com.codeflash.shaded.org.jacoco
org.objectweb.asm com.codeflash.shaded.org.objectweb.asm

SQLite is left unshaded (native library loading depends on exact resource paths).

Also includes:

  • Added jarHell and thirdPartyAudit to Gradle skip-validation init script as a safety net
  • Added Gradle wrapper (8.12) to codeflash-java-runtime
  • Synced JaCoCo dependencies to Gradle build (were Maven-only)

Verification

  • Maven build + tests pass
  • Gradle build + tests pass
  • jar tf confirms zero unshaded third-party classes remain (except SQLite)
  • com.codeflash.* public API is unchanged — shading is fully internal

🤖 Generated with Claude Code

…lasspath conflicts

Relocate Gson, Kryo, Objenesis, SLF4J, JaCoCo, and ASM under
com.codeflash.shaded.* in both Maven (shade plugin) and Gradle
(shadow plugin). SQLite is left unshaded due to native lib loading.

Also adds jarHell/thirdPartyAudit to the Gradle skip-validation init
script as a defensive measure, and adds Gradle wrapper + syncs JaCoCo
deps to the Gradle build.

Fixes OpenSearch jar-hell failures caused by duplicate com.google.gson
classes between the fat JAR and project dependencies.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@HeshamHM28 HeshamHM28 requested a review from mashraf-222 March 27, 2026 05:09
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 27, 2026

Claude finished @HeshamHM28's task in 1m 31s —— View job


PR Review Summary

  • Triage PR size → SMALL (42 additions, 3 deletions across 3 files)
  • Lint and type check → all prek checks passed, no issues
  • Resolve stale threads → none found
  • Code review
  • Duplicate detection

Prek Checks

All ruff and format checks passed. No issues.

Code Review

Bug: Gradle and Maven relocation rules are out of sync

The latest commit ("fix: shade args4j and EMMA transitive deps") added org.kohsuke and com.vladium relocations to pom.xml but did not update build.gradle.kts with the same rules.

Current state:

Package pom.xml build.gradle.kts
org.objectweb.asm ✅ shaded ✅ shaded
com.google.gson ✅ shaded ✅ shaded
com.esotericsoftware ✅ shaded ✅ shaded
org.objenesis ✅ shaded ✅ shaded
org.slf4j ✅ shaded ✅ shaded
org.jacoco ✅ shaded ✅ shaded
org.kohsuke (args4j) ✅ shaded missing
com.vladium (EMMA) ✅ shaded missing

Any project using a Gradle-built JAR will still have org/kohsuke/args4j/ and com/vladium/emma/rt/ unshaded on the classpath. The two missing relocations should be added to build.gradle.kts:

relocate("org.kohsuke", "com.codeflash.shaded.org.kohsuke")
relocate("com.vladium", "com.codeflash.shaded.com.vladium")

Fix this →

Duplicate Detection

No duplicates detected.


Last updated: 2026-03-31

@mashraf-222
Copy link
Copy Markdown
Contributor

Two JaCoCo CLI transitive deps are still unshaded in the fat JAR:

  • org/kohsuke/args4j/ (~30 classes) — old CLI parser, most projects use picocli/JCommander now
  • com/vladium/emma/rt/ (2 classes) — dead EMMA coverage project

Low collision risk, but for completeness:

<relocation>
    <pattern>org.kohsuke</pattern>
    <shadedPattern>com.codeflash.shaded.org.kohsuke</shadedPattern>
</relocation>
<relocation>
    <pattern>com.vladium</pattern>
    <shadedPattern>com.codeflash.shaded.com.vladium</shadedPattern>
</relocation>

Add relocation rules for org.kohsuke (args4j) and com.vladium (EMMA RT)
to prevent classpath conflicts from unshaded JaCoCo CLI transitive deps.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@HeshamHM28 HeshamHM28 enabled auto-merge March 31, 2026 07:30
@HeshamHM28 HeshamHM28 disabled auto-merge March 31, 2026 07:30
@HeshamHM28 HeshamHM28 merged commit e073592 into main Mar 31, 2026
31 of 32 checks passed
@HeshamHM28 HeshamHM28 deleted the cf-shaded-runtime-jar branch March 31, 2026 07:50
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