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 api/shadow.api
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ public class com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNotic
public final fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
public fun getOrganizationName ()Lorg/gradle/api/provider/Property;
public fun getOrganizationURL ()Lorg/gradle/api/provider/Property;
public fun getOutputPath ()Lorg/gradle/api/provider/Property;
public fun getPreamble1 ()Lorg/gradle/api/provider/Property;
public fun getPreamble2 ()Lorg/gradle/api/provider/Property;
public fun getPreamble3 ()Lorg/gradle/api/provider/Property;
Expand Down
1 change: 1 addition & 0 deletions docs/changes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Expose `patternSet` of `ServiceFileTransformer` as `public`. ([#1849](https://github.com/GradleUp/shadow/pull/1849))
- Expose `patternSet` of `ApacheLicenseResourceTransformer` as `public`. ([#1850](https://github.com/GradleUp/shadow/pull/1850))
- Expose `patternSet` of `ApacheNoticeResourceTransformer` as `public`. ([#1850](https://github.com/GradleUp/shadow/pull/1850))
- Support overriding output path of `ApacheNoticeResourceTransformer`. ([#1851](https://github.com/GradleUp/shadow/pull/1851))

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,45 @@ class TransformersTest : BaseTransformerTest() {
}
}

@Test
fun overrideOutputPathOfNoticeFile() {
val noticeEntry = "META-INF/NOTICE"
val customNoticeEntry = "META-INF/CUSTOM_NOTICE"
val one = buildJarOne {
insert(noticeEntry, "Notice from A")
}
val two = buildJarTwo {
insert(noticeEntry, "Notice from B")
}
projectScript.appendText(
transform<ApacheNoticeResourceTransformer>(
dependenciesBlock = implementationFiles(one, two),
transformerBlock = "addHeader = false; outputPath = '$customNoticeEntry'",
),
)

runWithSuccess(shadowJarPath)

assertThat(outputShadowedJar).useAll {
containsOnly(
customNoticeEntry,
*manifestEntries,
)
getContent(customNoticeEntry).isEqualTo(
"""
Copyright 2006-2025 The Apache Software Foundation

This product includes software developed at
The Apache Software Foundation (https://www.apache.org/).

Notice from A

Notice from B
""".trimIndent(),
)
}
}

@ParameterizedTest
@MethodSource("transformerConfigProvider")
fun otherTransformers(pair: Pair<String, KClass<*>>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ public open class ApacheNoticeResourceTransformer(
@get:Input
public open val charsetName: Property<String> = objectFactory.property(Charsets.UTF_8.name())

/**
* The output path of the `NOTICE` file.
*
* Defaults to `META-INF/NOTICE`.
*/
@get:Input
public open val outputPath: Property<String> = objectFactory.property(NOTICE_PATH)

@Inject
public constructor(objectFactory: ObjectFactory) : this(
objectFactory,
Expand Down Expand Up @@ -190,7 +198,7 @@ public open class ApacheNoticeResourceTransformer(
}
}

os.putNextEntry(zipEntry(NOTICE_PATH, preserveFileTimestamps))
os.putNextEntry(zipEntry(outputPath.get(), preserveFileTimestamps))
os.write(sb.toString().trim().toByteArray(charset))
os.closeEntry()

Expand Down