Skip to content

Commit 077cc9f

Browse files
committed
Update the Java library example
1 parent f6bdb5e commit 077cc9f

4 files changed

Lines changed: 13 additions & 14 deletions

File tree

‎KeepAnnotationsSample/README.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ plugins {
3434
* Register a new task that can generate the artifact with keep rules.
3535

3636
```kotlin
37-
val outputJar = project.tasks.named<org.gradle.jvm.tasks.Jar>("jar").flatMap { task ->
38-
task.archiveFile
37+
val jarTask = project.tasks.named<org.gradle.jvm.tasks.Jar>("jar")
38+
val outputJar = jarTask.flatMap { it.archiveFile }
39+
val outputFile = jarTask.flatMap { it.archiveFileName }.map { fileName ->
40+
"keep${fileName.uppercaseFirstChar()}"
3941
}
4042

41-
val outputFile = outputJar.map { file -> "keep${file.asFile.name.uppercaseFirstChar()}" }
42-
4343
// Register the JAR transform for extracting keep rules.
4444
val artifactTask = annotationKeep.registerJavaArchiveTransform(
4545
taskName = "keepRulesJar",
@@ -54,7 +54,7 @@ val artifactTask = annotationKeep.registerJavaArchiveTransform(
5454
// Register the new artifact.
5555
project.configurations.configureEach {
5656
if (name == "apiElements" || name == "runtimeElements") {
57-
outgoing.artifact(artifactTask)
57+
outgoing.artifact(artifactTask.flatMap { it.outputJar })
5858
}
5959
}
6060
```

‎KeepAnnotationsSample/app/build.gradle.kts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ dependencies {
5050
implementation(libs.androidx.core.ktx)
5151
implementation(libs.androidx.lifecycle.runtime.ktx)
5252
testImplementation(libs.junit)
53-
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
5453
androidTestImplementation(libs.androidx.espresso.core)
5554
androidTestImplementation(libs.androidx.junit)
5655
debugImplementation(libs.androidx.compose.ui.test.manifest)

‎KeepAnnotationsSample/gradle/libs.versions.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
agp = "9.5.0-alpha04"
2+
agp = "9.5.0-alpha05"
33
annotationKeep = "1.0.0-SNAPSHOT"
44
coreKtx = "1.19.0"
55
junit = "4.13.2"
@@ -9,8 +9,8 @@ lifecycleRuntimeKtx = "2.11.0"
99
activityCompose = "1.13.0"
1010
kotlin = "2.4.20"
1111
composeBom = "2026.08.00"
12-
appcompat = "1.6.1"
13-
material = "1.10.0"
12+
appcompat = "1.8.0"
13+
material = "1.14.0"
1414
jetbrainsKotlinJvm = "2.4.20"
1515

1616
[libraries]

‎KeepAnnotationsSample/java-library/build.gradle.kts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ java {
1111
targetCompatibility = JavaVersion.VERSION_11
1212
}
1313

14-
val outputJar = project.tasks.named<org.gradle.jvm.tasks.Jar>("jar").flatMap { task ->
15-
task.archiveFile
14+
val jarTask = project.tasks.named<org.gradle.jvm.tasks.Jar>("jar")
15+
val outputJar = jarTask.flatMap { it.archiveFile }
16+
val outputFile = jarTask.flatMap { it.archiveFileName }.map { fileName ->
17+
"keep${fileName.uppercaseFirstChar()}"
1618
}
1719

18-
val outputFile = outputJar.map { file -> "keep${file.asFile.name.uppercaseFirstChar()}" }
19-
2020
// Register the JAR transform for extracting keep rules.
2121
val artifactTask = annotationKeep.registerJavaArchiveTransform(
2222
taskName = "keepRulesJar",
@@ -27,7 +27,7 @@ val artifactTask = annotationKeep.registerJavaArchiveTransform(
2727
// Register the new artifact.
2828
project.configurations.configureEach {
2929
if (name == "apiElements" || name == "runtimeElements") {
30-
outgoing.artifact(artifactTask)
30+
outgoing.artifact(artifactTask.flatMap { it.outputJar })
3131
}
3232
}
3333

0 commit comments

Comments
 (0)