Skip to content

Commit 2bcdb85

Browse files
ikhoonminwoox
andauthored
Fix :core:shadedClasses failure (#6514)
Motivation: ':core:shadedClasses' fails when JaCoCo report is enabled by `-Pcoverage` because `shadedClasses` is only used in the JaCoco task. ```java org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':core:shadedClasses'. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:135) at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:288) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:133) ... at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64) at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47) Caused by: org.gradle.api.InvalidUserDataException: Cannot expand ZIP '/home/runner/work/armeria/armeria/core/build/libs/armeria-1.33.3-SNAPSHOT-shaded.jar' as it does not exist. ``` https://github.com/line/armeria/blob/7148df07f3a7fe7cb4640fb1ca761cbaca8b347f/gradle/scripts/lib/java-coverage.gradle#L103 It seems that the `archiveClassifier.set('shaded')` configuration used when upgrading Gradle 9 is causing the problem. Based on the following two configurations, the path of archiveFile becomes `<artifact>-untrimmed-<version>-shaded.jar`. https://github.com/line/armeria/blob/7148df07f3a7fe7cb4640fb1ca761cbaca8b347f/gradle/scripts/lib/java-shade.gradle#L28 https://github.com/line/armeria/blob/7148df07f3a7fe7cb4640fb1ca761cbaca8b347f/gradle/scripts/lib/java-shade.gradle#L118 This is then renamed to `<artifact>-shaded-<version>-shaded.jar` by `trimShadedJar` task. However, since the input file of `shadedClasses` is `<artifact>-<version>-shaded.jar`, the task fails to fine the jar file. Modifications: - Generate the output file name correctly by removing `untrimmed` infix from the output jar file instead of renaming it to `shaded`. - Miscellaneous) Make `publishJarPublicationToMavenLocal` depend on `shadedTask` or `trimShadedJar` to run `publishToMavenLocal` successfully. Result: `:core:shadedClasses` runs correctly <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Updated build artifact naming conventions to improve clarity and consistency in generated outputs. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: minux <[email protected]>
1 parent 08f0b32 commit 2bcdb85

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

gradle/scripts/lib/java-publish.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ configure(projectsWithFlags('publish', 'java')) {
8181
}
8282
}
8383
}
84+
def shadedJarTask = tasks.findByName('trimShadedJar') ?: tasks.findByName('shadedJar')
85+
if (shadedJarTask != null) {
86+
tasks.publishJarPublicationToMavenLocal.dependsOn(shadedJarTask)
87+
}
8488
}
8589

8690
configure(projectsWithFlags('publish')) {

gradle/scripts/lib/java-shade.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ configure(relocatedProjects) {
113113
// NB: Configure in a new closure so that all relocated projects have a 'shadedJar' task.
114114
configure(relocatedProjects) {
115115
if (project.hasFlags('trim')) {
116-
// Task 'shadedJar' may produce a very large JAR. Rename it to '*-untrimmed-*.jar' and
116+
// Task 'shadedJar' may produce a very large JAR. Rename it to '<artifact>-untrimmed-<version>-shaded.jar' and
117117
// let the task 'trimShadedJar' produce the trimmed JAR from it.
118118
tasks.shadedJar.archiveBaseName.set("${tasks.jar.archiveBaseName.get()}-untrimmed")
119119

@@ -128,7 +128,9 @@ configure(relocatedProjects) {
128128
}
129129

130130
def shadedFile = tasks.shadedJar.archiveFile.get().asFile
131-
def shadedAndTrimmedFile = file(shadedFile.path.replaceFirst('-untrimmed-', '-shaded-'))
131+
// Rename the output file to '<artifact>-<version>-shaded.jar' by removing '-untrimmed' from
132+
// the input file name.
133+
def shadedAndTrimmedFile = file(shadedFile.path.replaceFirst('-untrimmed-', '-'))
132134

133135
injars shadedFile
134136
// NB: By specifying 'outjars' *before* other 'injars' below, ProGuard will put only the classes

0 commit comments

Comments
 (0)