Skip to content

Commit 0bd4d62

Browse files
authored
Correct inheritFrom usages in Kotlin DSL (#1261)
* Tweak the sample code about using inheritFrom * Test `canInheritFromOtherManifest`
1 parent 433dae0 commit 0bd4d62

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/docs/configuration/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,13 @@ If it is desired to inherit a manifest from a JAR task other than the standard `
8989
on the `shadowJar.manifest` object can be used to configure the upstream.
9090

9191
```groovy
92-
tasks.register('testJar', Jar) {
92+
def testJar = tasks.register('testJar', Jar) {
9393
manifest {
9494
attributes 'Description': 'This is an application JAR'
9595
}
9696
}
9797
9898
tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
99-
manifest {
100-
inheritFrom(project.tasks.testJar.manifest)
101-
}
99+
manifest.inheritFrom(testJar.get().manifest)
102100
}
103101
```

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,4 +619,33 @@ class JavaPluginTest : BasePluginTest() {
619619
)
620620
}
621621
}
622+
623+
@Test
624+
fun canInheritFromOtherManifest() {
625+
projectScriptPath.appendText(
626+
"""
627+
jar {
628+
manifest {
629+
attributes 'Foo-Attr': 'Foo-Value'
630+
}
631+
}
632+
def testJar = tasks.register('testJar', Jar) {
633+
manifest {
634+
attributes 'Bar-Attr': 'Bar-Value'
635+
}
636+
}
637+
$shadowJar {
638+
manifest.inheritFrom(testJar.get().manifest)
639+
}
640+
""".trimIndent(),
641+
)
642+
643+
run(shadowJarTask)
644+
645+
assertThat(outputShadowJar).useAll {
646+
transform { it.manifest.mainAttributes }.isNotEmpty()
647+
getMainAttr("Foo-Attr").isEqualTo("Foo-Value")
648+
getMainAttr("Bar-Attr").isEqualTo("Bar-Value")
649+
}
650+
}
622651
}

0 commit comments

Comments
 (0)