Skip to content

Support shadowed sources JAR - #2265

Merged
Goooler merged 128 commits into
mainfrom
g/20260901/sources-jar
Oct 25, 2026
Merged

Goooler merged 128 commits into
mainfrom
g/20260901/sources-jar

Conversation

@Goooler

@Goooler Goooler commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

Closes #41.


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

@Goooler
Goooler force-pushed the g/20260901/sources-jar branch 3 times, most recently from 51fa468 to 7161bfa Compare September 2, 2026 06:38
@Goooler
Goooler force-pushed the g/20260901/sources-jar branch from 29523cb to 68c2e1b Compare September 2, 2026 07:06
@Goooler

This comment was marked as outdated.

This reverts commit 0100ab2.

### 1. Test Versions

| Commit Hash | Local Version Tag | Description |
| :--- | :--- | :--- |
| [`51d5feb5`](51d5feb) | `9.0.3-51d5feb5` | **Before Worker API** (single-threaded serial execution) |
| [`0100ab21`](0100ab2) | `9.0.3-0100ab21` | **After Worker API** (asynchronous parallel execution via Gradle Worker API) |

---

### 2. Detailed 10-Iteration Benchmark Results (Unit: ms)

| Iteration | Before Worker API (`51d5feb5`) | After Worker API (`0100ab21`) |
| :---: | :---: | :---: |
| **Warm-up 1** | 19,131.87 | 7,158.15 |
| **Warm-up 2** | 937.74 | 927.13 |
| **Warm-up 3** | 867.42 | 892.92 |
| **Build 1** | 949.85 | 887.27 |
| **Build 2** | 855.78 | 895.07 |
| **Build 3** | 870.54 | 913.32 |
| **Build 4** | 842.07 | 962.29 |
| **Build 5** | 834.61 | 902.32 |
| **Build 6** | 895.61 | 863.34 |
| **Build 7** | 842.98 | 882.96 |
| **Build 8** | 836.82 | 862.21 |
| **Build 9** | 843.10 | 888.14 |
| **Build 10** | 874.22 | 867.52 |

---

### 3. Summary Statistics

| Metric | Before Worker API (`51d5feb5`) | After Worker API (`0100ab21`) | Difference |
| :--- | :---: | :---: | :--- |
| **Mean** | **864.56 ms** | **892.44 ms** | +27.88 ms (+3.2%) |
| **Median** | **849.44 ms** | **891.17 ms** | +41.73 ms (+4.9%) |
| **Min** | **834.61 ms** | **862.21 ms** | +27.60 ms |
| **Max** | **949.85 ms** | **962.29 ms** | +12.44 ms |
@Goooler
Goooler force-pushed the g/20260901/sources-jar branch from ef198b2 to 3b604fc Compare September 24, 2026 15:30
- Deduplicate entry writing in generateSourcesJar.
- Remove the redundant slash branch in extractSourceSubpatterns, as
  converting a pattern and its prefix to dot or slash notation keeps
  `startsWith` the same.
- Remove the unused default offset from matchesSubpattern.
- Skip unrelated sources early in SimpleRelocator.applyToSourceContent,
  avoiding building subpatterns and regexes for sources that don't
  reference the pattern. Remapping 300 Guava sources with 1001 relocators
  went from ~25s to ~1.5s.
References like `getResource("/org/foo/x.properties")` are relocated in
class files, as `canRelocatePath` strips the leading slash, but were kept
as-is in the shadowed sources.
With class-level includes or excludes, a source file's path is relocated
per class like class files, but its `package` declaration can't match
those patterns. An excluded class kept its path but got a relocated
package, and an included class got the opposite. Set the declaration from
the relocated path for sources laid out in their package directories.
@Goooler
Goooler force-pushed the g/20260901/sources-jar branch from 4d1e45e to 8422270 Compare September 24, 2026 16:37
KGP's `jvm` publication publishes the non-shadowed JAR, so attaching the
shadowed sources JAR to it would publish mismatched sources and may clash
with KGP's own sources classifier. Publish the shadowed JAR and its
sources together in a dedicated publication instead.
Keeping `jar` enabled while `shadowJar` writes the same file in
`build/libs` has no ordering between them, so the published JAR depended
on which task finished last, which made its functional test flaky. The
overlapping outputs also disable caching for both tasks. Keep publishing
from the `shadow` component as the only documented replacement approach.
Add a `withSourcesJar` parameter to writeClientAndServerModules instead of
always enabling `withSourcesJar()`, so unrelated multi-project tests keep
covering the default path without generating shadowed sources JARs.

This comment was marked as outdated.

@Goooler
Goooler marked this pull request as ready for review September 24, 2026 18:01
# Conflicts:
#	src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt
#	src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/PublishingTest.kt
#	src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocator.kt
@Goooler
Goooler force-pushed the g/20260901/sources-jar branch from d481a67 to 58e3f00 Compare October 25, 2026 06:54

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.

) =
try {
zipOutStream.use { zos ->
val sourcesJars = includedSourcesJars.filter { it.exists() && it.isFile }.sortedBy { it.path }
Comment on lines +43 to +44
val pathWithoutExt = path.removeSuffix(".$extension")
val className = pathWithoutExt.replace('/', '.')
*/
override fun applyToSourceContent(sourceContent: String): String {
if (rawString) return sourceContent
if (rawString || pattern.isEmpty()) return sourceContent
Comment on lines +117 to +120
relocateSourcePattern(
sourceContent = sourceContent,
patternFrom = pattern,
patternTo = shadedPattern,
Comment on lines +264 to +267
for (pat in patterns) {
val dotPat = pat.replace('/', '.')
if (!dotPat.startsWith(dotPrefix)) continue
val sub = dotPat.substring(dotPrefix.length).replaceFirst(trailingWildcardRegex, "")
@Goooler
Goooler enabled auto-merge (squash) October 25, 2026 07:40
@Goooler
Goooler merged commit 5e8dda2 into main Oct 25, 2026
10 checks passed
@Goooler
Goooler deleted the g/20260901/sources-jar branch October 25, 2026 07:46
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.

Creating a source jar reflecting the "uber jar"

2 participants