Skip to content

Commit 482d0b5

Browse files
authored
Merge pull request awsdocs#426 from awsdocs/blank-java-maven
For blank-java, support Maven in 2-build-layer.sh script
2 parents ec207b8 + 4742188 commit 482d0b5

File tree

5 files changed

+74
-4
lines changed

5 files changed

+74
-4
lines changed
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
#!/bin/bash
22
set -eo pipefail
3-
gradle -q packageLibs
4-
mv build/distributions/blank-java.zip build/blank-java-lib.zip
3+
4+
if [ $1 ]
5+
then
6+
if [ $1 = mvn ]
7+
then
8+
mvn prepare-package
9+
fi
10+
else
11+
gradle -q packageLibs
12+
mv build/distributions/blank-java.zip build/blank-java-lib.zip
13+
fi

sample-apps/blank-java/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ To build a Lambda layer that contains the function's runtime dependencies, run `
4343

4444
blank-java$ ./2-build-layer.sh
4545

46+
You can also run this commnand with Maven. To use Maven, add `mvn` to the command.
47+
48+
blank-java$ ./2-build-layer.sh mvn
49+
4650
# Deploy
4751

4852
To deploy the application, run `3-deploy.sh`.
@@ -55,7 +59,7 @@ To deploy the application, run `3-deploy.sh`.
5559

5660
This script uses AWS CloudFormation to deploy the Lambda functions and an IAM role. If the AWS CloudFormation stack that contains the resources already exists, the script updates it with any changes to the template or function code.
5761

58-
You can also build the application with Maven. To use maven, add `mvn` to the command.
62+
You can also build the application with Maven. To use Maven, add `mvn` to the command.
5963

6064
java-basic$ ./3-deploy.sh mvn
6165
[INFO] Scanning for projects...

sample-apps/blank-java/pom.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,44 @@
9090
</execution>
9191
</executions>
9292
</plugin>
93+
<plugin>
94+
<groupId>org.apache.maven.plugins</groupId>
95+
<artifactId>maven-dependency-plugin</artifactId>
96+
<executions>
97+
<execution>
98+
<id>copy-dependencies</id>
99+
<phase>prepare-package</phase>
100+
<goals>
101+
<goal>copy-dependencies</goal>
102+
</goals>
103+
<configuration>
104+
<outputDirectory>
105+
${project.build.directory}/classes/java/lib
106+
</outputDirectory>
107+
<includeScope>runtime</includeScope>
108+
<excludeScope>test</excludeScope>
109+
</configuration>
110+
</execution>
111+
</executions>
112+
</plugin>
113+
<plugin>
114+
<groupId>org.apache.maven.plugins</groupId>
115+
<artifactId>maven-assembly-plugin</artifactId>
116+
<executions>
117+
<execution>
118+
<phase>prepare-package</phase>
119+
<goals>
120+
<goal>single</goal>
121+
</goals>
122+
<configuration>
123+
<appendAssemblyId>false</appendAssemblyId>
124+
<descriptors>
125+
<descriptor>zip.xml</descriptor>
126+
</descriptors>
127+
</configuration>
128+
</execution>
129+
</executions>
130+
</plugin>
93131
<plugin>
94132
<groupId>org.apache.maven.plugins</groupId>
95133
<artifactId>maven-compiler-plugin</artifactId>

sample-apps/blank-java/template-mvn.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ Resources:
2525
Properties:
2626
LayerName: blank-java-lib
2727
Description: Dependencies for the blank-java sample app.
28-
ContentUri: build/blank-java-lib.zip
28+
ContentUri: target/blank-java-1.0-SNAPSHOT.zip
2929
CompatibleRuntimes:
3030
- java11

sample-apps/blank-java/zip.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
4+
<id>zip</id>
5+
<includeBaseDirectory>false</includeBaseDirectory>
6+
7+
<formats>
8+
<format>zip</format>
9+
</formats>
10+
<fileSets>
11+
<fileSet>
12+
<directory>${project.build.directory}/classes/java</directory>
13+
<outputDirectory>java/</outputDirectory>
14+
<excludes>
15+
<exclude>example/</exclude>
16+
</excludes>
17+
</fileSet>
18+
</fileSets>
19+
</assembly>

0 commit comments

Comments
 (0)