Skip to content

Commit

Permalink
Fail builds if processing bad jars (GradleUp#1146)
Browse files Browse the repository at this point in the history
Co-authored-by: Carlos Lopez <carlopez@squareup.com>
  • Loading branch information
Goooler and charlie-lobo authored Jan 12, 2025
1 parent 770109a commit a671b71
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/docs/changes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
Some public `List` parameters are also changed to `Set`.
- Replace deprecated `SelfResolvingDependency` with `FileCollectionDependency`. ([#1114](https://github.com/GradleUp/shadow/pull/1114))

**Fixed**

- Fail builds if processing bad jars. ([#1146](https://github.com/GradleUp/shadow/pull/1146))


## [v9.0.0-beta4] (2024-12-06)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.jengelman.gradle.plugins.shadow

import assertk.all
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.isEqualTo
Expand All @@ -18,6 +19,7 @@ import kotlin.io.path.readText
import kotlin.io.path.writeText
import org.gradle.api.plugins.JavaPlugin
import org.gradle.testfixtures.ProjectBuilder
import org.gradle.testkit.runner.TaskOutcome.FAILED
import org.gradle.testkit.runner.TaskOutcome.SUCCESS
import org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE
import org.junit.jupiter.api.Disabled
Expand Down Expand Up @@ -830,6 +832,33 @@ class ShadowPluginTest : BasePluginTest() {
assertThat(result.output).contains("Reusing configuration cache.")
}

@Issue(
"https://github.com/GradleUp/shadow/issues/915",
)
@Test
fun failBuildIfProcessingBadJar() {
val badJarPath = path("bad.jar").apply {
writeText("A bad jar.")
}.toUri().toURL().path

projectScriptPath.appendText(
"""
dependencies {
implementation files('$badJarPath')
}
""".trimIndent(),
)

val result = runWithFailure(shadowJarTask)

assertThat(result).all {
taskOutcomeEquals(shadowJarTask, FAILED)
transform { it.output }.contains(
"java.util.zip.ZipException: archive is not a ZIP archive",
)
}
}

private fun writeShadowedClientAndServerModules() {
writeClientAndServerModules()
path("client/build.gradle").appendText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public open class ShadowCopyAction internal constructor(
"See: ${documentationRegistry.getDslRefForProperty(Zip::class.java, "zip64")}",
)
}
// Rethrow the exception like `java.util.zip.ZipException: archive is not a ZIP archive`.
throw e
}
return WorkResults.didWork(true)
}
Expand Down

0 comments on commit a671b71

Please sign in to comment.