Skip to content

Commit 0187e75

Browse files
authored
Fix resolving BOM dependencies when minimize is enabled (#1637)
* Test `minimizeBomDependency` * Skip `ExternalModuleDependency` * Update changelog * Avoid NPE * Tweak test
1 parent b511836 commit 0187e75

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

docs/changes/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Fix missing space in `ApacheNoticeResourceTransformer` preamble causing malformed NOTICE header. ([#1623](https://github.com/GradleUp/shadow/pull/1623)).
99
- Fix using `ApacheNoticeResourceTransformer` without `projectName`. ([#1627](https://github.com/GradleUp/shadow/pull/1627)).
1010
- Fix extra indents of `ApacheNoticeResourceTransformer` output. ([#1628](https://github.com/GradleUp/shadow/pull/1628)).
11+
- Fix resolving BOM dependencies when `minimize` is enabled. ([#1637](https://github.com/GradleUp/shadow/pull/1637)).
1112

1213
## [9.0.1](https://github.com/GradleUp/shadow/releases/tag/9.0.1) - 2025-08-09
1314

src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/MinimizeTest.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,36 @@ class MinimizeTest : BasePluginTest() {
279279
}
280280
}
281281

282+
@Issue(
283+
"https://github.com/GradleUp/shadow/issues/1636",
284+
)
285+
@Test
286+
fun minimizeBomDependency() {
287+
writeApiLibAndImplModules()
288+
path("impl/build.gradle").appendText(
289+
"""
290+
dependencies {
291+
api platform('org.jetbrains.kotlin:kotlin-bom:2.2.0')
292+
}
293+
""".trimIndent(),
294+
)
295+
296+
run(":impl:$SHADOW_JAR_TASK_NAME")
297+
298+
assertThat(jarPath("impl/build/libs/impl-all.jar")).useAll {
299+
containsAtLeast(
300+
"api/",
301+
"lib/",
302+
"impl/",
303+
"impl/SimpleEntity.class",
304+
"api/Entity.class",
305+
"api/UnusedEntity.class",
306+
"lib/LibEntity.class",
307+
*manifestEntries,
308+
)
309+
}
310+
}
311+
282312
private fun writeApiLibAndImplModules() {
283313
settingsScript.appendText(
284314
"""

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/UnusedTracker.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java.io.File
44
import org.gradle.api.Project
55
import org.gradle.api.artifacts.Configuration
66
import org.gradle.api.artifacts.Dependency
7+
import org.gradle.api.artifacts.ExternalModuleDependency
78
import org.gradle.api.artifacts.FileCollectionDependency
89
import org.gradle.api.artifacts.ProjectDependency
910
import org.gradle.api.file.FileCollection
@@ -54,9 +55,12 @@ internal class UnusedTracker(
5455
is FileCollectionDependency -> {
5556
apiJars.addAll(dep.files)
5657
}
58+
// Skip BOM dependencies and other non-JAR dependencies.
59+
is ExternalModuleDependency -> Unit
5760
else -> {
5861
addJar(runtimeConfiguration, dep, apiJars)
59-
apiJars.add(runtimeConfiguration.find { it.name.startsWith("${dep.name}-") } as File)
62+
val jarFile = runtimeConfiguration.find { it.name.startsWith("${dep.name}-") } ?: return@forEach
63+
apiJars.add(jarFile)
6064
}
6165
}
6266
}

0 commit comments

Comments
 (0)