fix(gradle): exclude non-jar archive artifacts - #927
xujiantop-crypto wants to merge 1 commit into
Conversation
| } | ||
|
|
||
| def artifactJars = t.project.configurations.archives.artifacts.files.files | ||
| def artifactJars = t.project.configurations.archives.artifacts.findAll { it.extension == 'jar' }*.file |
There was a problem hiding this comment.
[ERROR_HANDLING] Filtering by extension can now yield an empty artifactJars, and nothing downstream detects that. copyToArtifactDir skips the extraction loop, still creates lib/ and copies the runtime classpath, and JavaGradleCopyArtifactsAction copies build/distributions/lambda-build without checking its contents. The result is a build that reports success but produces a Lambda package with dependencies and no handler classes, failing at invoke time with ClassNotFoundException instead of at build time.
Before this change any archive in archives was extracted, so the "no output at all" outcome was not reachable. It becomes reachable for projects whose only registered archive is a non-jar (e.g. jar.enabled = false plus a custom Zip/distZip artifact).
A fail-fast guard matches the existing convention in this file (buildDirForProject and assertExpectedBuildDir both throw RuntimeException on invariant violations):
def artifactJars = t.project.configurations.archives.artifacts.findAll { it.extension == 'jar' }*.file
if (artifactJars.isEmpty()) {
throw new RuntimeException("No JAR artifacts found in the 'archives' configuration of project ${t.project.name}")
}The new integration test only covers the mixed case (jar plus zip), so this path is currently untested; a fixture with a non-jar-only archives configuration would pin the intended behaviour.
Issue #, if available:
Fixes #138
Description of changes
archivesconfiguration before extracting Lambda build outputDescription of how you validated changes
python -m pytest tests/unit/workflows/java_gradle -q— 53 passedpython -m pytest "tests/integration/workflows/java_gradle/test_java_gradle.py::TestJavaGradle_0_java8::test_build_single_build_excludes_non_jar_archives" -q -s— 1 passedpython -m ruff check aws_lambda_buildersgit diff --checkChecklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.