aws / aws/aws-lambda-builders

JavaGradleWorkflow includes extraneous files if other archive artifacts are defined

Offen
#138 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area/workflow/java_gradle maintainer/need-response
Vorherrschende Sprache
Python
Sterne
380
Forks
161
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
2

Beschreibung

**Description:**

In certain Gradle projects, running `sam build` may include files in the bundle that aren't needed.
This occurs because the logic for grabbing the project's jar is actually pulling the contents of all defined archive artifacts, some of which may be for other purposes entirely. In most cases, this doesn't "break" anything, but just increases the size of the deployment bundle silently.

One example of a situation that would cause this is a Java project with the built-in "application" plugin applied, which then produces additional zip and tar distribution artifacts.

https://github.com/awslabs/aws-lambda-builders/blob/develop/aws_lambda_builders/workflows/java_gradle/resources/lambda-build-init.gradle#L62

One potential fix would be to change https://github.com/awslabs/aws-lambda-builders/blob/develop/aws_lambda_builders/workflows/java_gradle/resources/lambda-build-init.gradle#L27 from `def artifactJars = t.project.configurations.archives.artifacts.files.files` to `def artifactJars = configurations.archives.artifacts.findAll { it.extension == 'jar' }*.file`.

**Steps to reproduce the issue:**
1. Run `sam init --runtime java8 --dependency-manager gradle --name gradlebuildtest`
2. Run `cd gradlebuildtest/`
3. Run `sam build && find .aws-sam/build/HelloWorldFunction -type f` (Expected result)
4. Remove the previous result: `rm -rf .aws-sam/`
5. Edit `HelloWorldFunction/build.gradle` as follows
* Add `id 'application'` to the `plugins` block
* Add `mainClassName = 'helloworld.App'` (it's not actually executable yet, but that doesn't matter for demonstrating this behavior)
6. Run `sam build && find .aws-sam/build/HelloWorldFunction -type f` (Observed result)
7. Note that there is now an unnecessary `HelloWorldFunction` directory included.

**Observed result:**

```
mac-dcarr:gradlebuildtest dcarr$ sam build && find .aws-sam/build/HelloWorldFunction -type f
Building resource 'HelloWorldFunction'
Running JavaGradleWorkflow:GradleBuild
Running JavaGradleWorkflow:CopyArtifacts

Build Succeeded

Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml

Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Package: sam package --s3-bucket

.aws-sam/build/HelloWorldFunction/helloworld/GatewayResponse.class
.aws-sam/build/HelloWorldFunction/helloworld/App.class
.aws-sam/build/HelloWorldFunction/HelloWorldFunction/bin/HelloWorldFunction
.aws-sam/build/HelloWorldFunction/HelloWorldFunction/bin/HelloWorldFunction.bat
.aws-sam/build/HelloWorldFunction/HelloWorldFunction/lib/aws-lambda-java-core-1.2.0.jar
.aws-sam/build/HelloWorldFunction/HelloWorldFunction/lib/HelloWorldFunction.jar
.aws-sam/build/HelloWorldFunction/META-INF/MANIFEST.MF
.aws-sam/build/HelloWorldFunction/lib/aws-lambda-java-core-1.2.0.jar
mac-dcarr:gradlebuildtest dcarr$
```

**Expected result:**

```
mac-dcarr:gradlebuildtest dcarr$ sam build && find .aws-sam/build/HelloWorldFunction -type f
Building resource 'HelloWorldFunction'
Running JavaGradleWorkflow:GradleBuild
Running JavaGradleWorkflow:CopyArtifacts

Build Succeeded

Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml

Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Package: sam package --s3-bucket

.aws-sam/build/HelloWorldFunction/helloworld/GatewayResponse.class
.aws-sam/build/HelloWorldFunction/helloworld/App.class
.aws-sam/build/HelloWorldFunction/META-INF/MANIFEST.MF
.aws-sam/build/HelloWorldFunction/lib/aws-lambda-java-core-1.2.0.jar
mac-dcarr:gradlebuildtest dcarr$
```

**Additional environment details (Ex: Windows, Mac, Amazon Linux etc)**

Scripts were run on Mac OS X 10.14.6; SAM CLI, version 0.23.0.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit aws_lambda_builders/workflows/java_gradle/resources/lambda-build-init.gradle, insbesondere mit der Auswahl des Archivartefakts und den GradleBuild- und CopyArtifacts-Schritten von JavaGradleWorkflow. Reproduziere das Problem mit den dokumentierten Befehlen sam init, application-plugin edit, sam build und find. Das Ziel ist erreicht, wenn der Build die Anwendungsklassen und Dependency-JARs ohne das unnötige Anwendungsverzeichnis der Distribution und dessen Dateien enthält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
build-system
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.