Skip to content

Commit 8b6090e

Browse files
authored
Fix excluding dependencies whose versions contain + (#1597)
* Test `filterProjectThatVersionContainsPlus` * Update checks in `Dependency.toSpec` * Update changelog
1 parent 99da366 commit 8b6090e

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

docs/changes/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
The Gradle Module descriptors (`org.codehaus.groovy.runtime.ExtensionModule` files) defined under `META-INF/services/`
1616
and `META-INF/groovy` will be merged into `META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule`.
1717

18+
### Fixed
19+
20+
- Fix excluding dependencies whose versions contain `+`. ([#1597](https://github.com/GradleUp/shadow/pull/1597))
21+
1822
## [9.1.0](https://github.com/GradleUp/shadow/compare/9.1.0) - 2025-08-29
1923

2024
### Added

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.jengelman.gradle.plugins.shadow
22

33
import assertk.assertThat
4+
import com.github.jengelman.gradle.plugins.shadow.util.Issue
45
import com.github.jengelman.gradle.plugins.shadow.util.containsOnly
56
import kotlin.io.path.appendText
67
import kotlin.io.path.writeText
@@ -174,6 +175,32 @@ class FilteringTest : BasePluginTest() {
174175
}
175176
}
176177

178+
@Issue(
179+
"https://github.com/GradleUp/shadow/issues/671",
180+
)
181+
@Test
182+
fun filterProjectThatVersionContainsPlus() {
183+
writeClientAndServerModules(
184+
serverShadowBlock = """
185+
dependencies {
186+
exclude(project(':client'))
187+
}
188+
""".trimIndent(),
189+
)
190+
path("client/build.gradle").appendText("version = '1.0.0+1'")
191+
192+
run(serverShadowJarPath)
193+
194+
assertThat(outputServerShadowedJar).useAll {
195+
containsOnly(
196+
"server/",
197+
"server/Server.class",
198+
*junitEntries,
199+
*manifestEntries,
200+
)
201+
}
202+
}
203+
177204
@Test
178205
fun excludeTransitiveProjectDependency() {
179206
writeClientAndServerModules(

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/DependencyFilter.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,19 @@ public interface DependencyFilter : Serializable {
109109

110110
private fun Dependency.toSpec(): Spec<ResolvedDependency> {
111111
return Spec<ResolvedDependency> { resolvedDependency ->
112-
(group == null || resolvedDependency.moduleGroup.matches(group!!.toRegex())) &&
113-
resolvedDependency.moduleName.matches(name.toRegex()) &&
114-
(version == null || resolvedDependency.moduleVersion.matches(version!!.toRegex()))
112+
val groupMatch = group?.let {
113+
it == resolvedDependency.moduleGroup || resolvedDependency.moduleGroup.matches(it.toRegex())
114+
} ?: true
115+
val nameMatch = name.let {
116+
it == resolvedDependency.moduleName || resolvedDependency.moduleName.matches(it.toRegex())
117+
}
118+
val versionMatch = version?.let {
119+
// Version like `1.0.0+1` can't be converted to regex directly because `+` is a special character in regex.
120+
// So we check for exact match first, then fallback to regex match.
121+
it == resolvedDependency.moduleVersion || resolvedDependency.moduleVersion.matches(it.toRegex())
122+
} ?: true
123+
124+
groupMatch && nameMatch && versionMatch
115125
}
116126
}
117127
}

0 commit comments

Comments
 (0)