Skip to content

Commit

Permalink
Correct inheritFrom usages in Kotlin DSL (#1261)
Browse files Browse the repository at this point in the history
* Tweak the sample code about using inheritFrom

* Test `canInheritFromOtherManifest`
  • Loading branch information
Goooler authored Feb 18, 2025
1 parent 433dae0 commit 0bd4d62
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/docs/configuration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,13 @@ If it is desired to inherit a manifest from a JAR task other than the standard `
on the `shadowJar.manifest` object can be used to configure the upstream.

```groovy
tasks.register('testJar', Jar) {
def testJar = tasks.register('testJar', Jar) {
manifest {
attributes 'Description': 'This is an application JAR'
}
}
tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
manifest {
inheritFrom(project.tasks.testJar.manifest)
}
manifest.inheritFrom(testJar.get().manifest)
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -619,4 +619,33 @@ class JavaPluginTest : BasePluginTest() {
)
}
}

@Test
fun canInheritFromOtherManifest() {
projectScriptPath.appendText(
"""
jar {
manifest {
attributes 'Foo-Attr': 'Foo-Value'
}
}
def testJar = tasks.register('testJar', Jar) {
manifest {
attributes 'Bar-Attr': 'Bar-Value'
}
}
$shadowJar {
manifest.inheritFrom(testJar.get().manifest)
}
""".trimIndent(),
)

run(shadowJarTask)

assertThat(outputShadowJar).useAll {
transform { it.manifest.mainAttributes }.isNotEmpty()
getMainAttr("Foo-Attr").isEqualTo("Foo-Value")
getMainAttr("Bar-Attr").isEqualTo("Bar-Value")
}
}
}

0 comments on commit 0bd4d62

Please sign in to comment.