Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Remove runtime dependencies on Commons Codec and Commons IO by using JDK APIs. ([#2136](https://github.com/GradleUp/shadow/pull/2136))
- **POTENTIALLY BREAKING:** Remove `Serializable` from `DependencyFilter`. ([#2144](https://github.com/GradleUp/shadow/pull/2144))
- Bump default R8 from `9.1.31` to `9.2.23`. ([#2157](https://github.com/GradleUp/shadow/pull/2157))
- Allow repackaging Service file classes with R8. ([#2174](https://github.com/GradleUp/shadow/pull/2174))

### Deprecated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,19 @@ class ServiceFileTransformerTest : BaseTransformerTest() {
@Test
fun serviceResourceTransformerWithRelocation() {
val one = buildJarOne {
insert("com/example/Driver.class", createEmptyClassBytes("com/example/Driver"))
insert("foo/FooDriver.class", createEmptyClassBytes("foo/FooDriver"))
insert(
"META-INF/services/java.sql.Driver",
"""
|oracle.jdbc.OracleDriver
|org.apache.hive.jdbc.HiveDriver
"""
.trimMargin(),
)
insert(
"META-INF/services/org.apache.axis.components.compiler.Compiler",
"org.apache.axis.components.compiler.Javac",
)
insert(
"META-INF/services/org.apache.commons.logging.LogFactory",
"org.apache.commons.logging.impl.LogFactoryImpl",
"META-INF/services/com.example.Driver",
"foo.FooDriver",
)
}
val two = buildJarTwo {
insert("bar/BarDriver.class", createEmptyClassBytes("bar/BarDriver"))
insert(
"META-INF/services/java.sql.Driver",
"""
|org.apache.derby.jdbc.AutoloadedDriver
|com.mysql.jdbc.Driver
"""
.trimMargin(),
)
insert(
"META-INF/services/org.apache.axis.components.compiler.Compiler",
"org.apache.axis.components.compiler.Jikes",
"META-INF/services/com.example.Driver",
"bar.BarDriver",
)
insert("META-INF/services/org.apache.commons.logging.LogFactory", "org.mortbay.log.Factory")
}

projectScript.appendText(
Expand All @@ -85,10 +67,9 @@ class ServiceFileTransformerTest : BaseTransformerTest() {
|}
|$shadowJarTask {
| mergeServiceFiles()
| relocate("org.apache", "myapache") {
| exclude 'org.apache.axis.components.compiler.Jikes'
| exclude 'org.apache.commons.logging.LogFactory'
| }
| relocate("com.example", "relocated.com.example")
| relocate("foo", "relocated.foo")
| relocate("bar", "relocated.bar")
|}
"""
.trimMargin()
Expand All @@ -97,29 +78,24 @@ class ServiceFileTransformerTest : BaseTransformerTest() {
runWithSuccess(shadowJarPath)

assertThat(outputShadowedJar).useAll {
getContent("META-INF/services/java.sql.Driver")
.isEqualTo(
"""
|oracle.jdbc.OracleDriver
|myapache.hive.jdbc.HiveDriver
|myapache.derby.jdbc.AutoloadedDriver
|com.mysql.jdbc.Driver
"""
.trimMargin()
)
getContent("META-INF/services/myapache.axis.components.compiler.Compiler")
.isEqualTo(
"""
|myapache.axis.components.compiler.Javac
|org.apache.axis.components.compiler.Jikes
"""
.trimMargin()
)
getContent("META-INF/services/org.apache.commons.logging.LogFactory")
containsOnly(
"relocated/",
"relocated/bar/",
"relocated/bar/BarDriver.class",
"relocated/com/",
"relocated/com/example/",
"relocated/com/example/Driver.class",
"relocated/foo/",
"relocated/foo/FooDriver.class",
"META-INF/services/",
"META-INF/services/relocated.com.example.Driver",
*manifestEntries,
)
getContent("META-INF/services/relocated.com.example.Driver")
.isEqualTo(
"""
|myapache.commons.logging.impl.LogFactoryImpl
|org.mortbay.log.Factory
|relocated.foo.FooDriver
|relocated.bar.BarDriver
"""
.trimMargin()
)
Expand Down Expand Up @@ -168,22 +144,23 @@ class ServiceFileTransformerTest : BaseTransformerTest() {

assertThat(outputShadowedJar).useAll {
containsOnly(
"bar/",
"bar/BarDriver.class",
"com/",
"com/example/",
"com/example/Driver.class",
"foo/",
"foo/FooDriver.class",
"relocated/",
"relocated/bar/",
"relocated/bar/BarDriver.class",
"relocated/com/",
"relocated/com/example/",
"relocated/com/example/Driver.class",
"relocated/foo/",
"relocated/foo/FooDriver.class",
"META-INF/services/",
"META-INF/services/com.example.Driver",
"META-INF/services/relocated.com.example.Driver",
*manifestEntries,
)
getContent("META-INF/services/com.example.Driver")
getContent("META-INF/services/relocated.com.example.Driver")
.isEqualTo(
"""
|foo.FooDriver
|bar.BarDriver
|relocated.foo.FooDriver
|relocated.bar.BarDriver
|"""
.trimMargin()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ private fun serviceProguardRules(inputJar: File): List<String> {
.forEach { entry ->
val serviceClass = entry.name.removePrefix(SERVICES_PATH).replace('/', '.')
if (serviceClass.isJavaTypeName()) {
rules += "-keep class $serviceClass { *; }"
rules += "-keep,allowrepackage class $serviceClass { *; }"
Comment thread
Goooler marked this conversation as resolved.
}
jarFile.getInputStream(entry).bufferedReader().useLines { lines ->
lines
.map { it.substringBefore('#').trim() }
.filter { it.isNotEmpty() && it.isJavaTypeName() }
.forEach { provider -> rules += "-keep class $provider { *; }" }
.forEach { provider -> rules += "-keep,allowrepackage class $provider { *; }" }
}
}
}
Expand Down