Skip to content

fix(gradle): exclude non-jar archive artifacts - #927

Open
xujiantop-crypto wants to merge 1 commit into
aws:developfrom
xujiantop-crypto:fix/gradle-jar-artifacts
Open

xujiantop-crypto wants to merge 1 commit into
aws:developfrom
xujiantop-crypto:fix/gradle-jar-artifacts

Conversation

@xujiantop-crypto

Copy link
Copy Markdown

Issue #, if available:

Fixes #138

Description of changes

  • select only JAR artifacts from Gradle's archives configuration before extracting Lambda build output
  • add a non-JAR ZIP artifact to the Gradle integration fixtures for Java 8, 11, 17, and 21
  • verify the ZIP's Java source is not copied into the Lambda artifact

Description of how you validated changes

  • python -m pytest tests/unit/workflows/java_gradle -q — 53 passed
  • python -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 passed
  • python -m ruff check aws_lambda_builders
  • git diff --check

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@xujiantop-crypto
xujiantop-crypto requested a review from a team as a code owner September 17, 2026 03:24
@github-actions github-actions Bot added pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. area/workflow/java_gradle labels Sep 17, 2026

@aws-sam-tooling-bot aws-sam-tooling-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Results

Reviewed: 587257c..5bad886
Files: 6
Comments: 1

}

def artifactJars = t.project.configurations.archives.artifacts.files.files
def artifactJars = t.project.configurations.archives.artifacts.findAll { it.extension == 'jar' }*.file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/workflow/java_gradle pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JavaGradleWorkflow includes extraneous files if other archive artifacts are defined

1 participant