Skip to content

Commit 8d03249

Browse files
docs: Update gradle configuration readme (#1359)
* Update gradle configuration readme * Move into configuration * Starting gradle example * Remove * Start again * Update documentation for gradle * Clarify gradle versions a bit better * Starting gradle example * Cleanup gradle example * Build gradle example * Fix build hopefully * Add gradle wrapper * Formatting * Update docs/index.md Co-authored-by: Jérôme Van Der Linden <[email protected]> * Apply suggestions from code review Co-authored-by: Jérôme Van Der Linden <[email protected]> * Updated README with sam instructions --------- Co-authored-by: Jérôme Van Der Linden <[email protected]>
1 parent 787aa9d commit 8d03249

File tree

17 files changed

+767
-2
lines changed

17 files changed

+767
-2
lines changed

.github/workflows/build.yml

+5
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ jobs:
6363
cache: 'maven'
6464
- name: Build with Maven
6565
run: mvn -B install --file pom.xml
66+
- name: Build Gradle Example
67+
if: ${{ matrix.java == '8' }} # Gradle example can only be built on Java 8
68+
run: |
69+
cd examples/powertools-examples-core/gradle
70+
./gradlew build
6671
- name: Upload coverage to Codecov
6772
uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
6873
if: ${{ matrix.java == '11' }} # publish results once

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,5 @@ example/HelloWorldFunction/.gradle
107107
example/HelloWorldFunction/build
108108
/example/.gradle/
109109
/example/.java-version
110+
.gradle
111+
build/

README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,18 @@ Next, configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lam
130130
<summary><b>Gradle - Java 11+</b></summary>
131131

132132
```groovy
133+
133134
plugins {
134135
id 'java'
135-
id 'io.freefair.aspectj.post-compile-weaving' version '8.1.0'
136+
id 'io.freefair.aspectj.post-compile-weaving' version '8.2.2'
136137
}
137138
139+
// the freefair aspect plugins targets gradle 8.2.1
140+
// https://docs.freefair.io/gradle-plugins/8.2.2/reference/
141+
wrapper {
142+
gradleVersion = "8.2.1"
143+
}
144+
138145
repositories {
139146
mavenCentral()
140147
}
@@ -143,6 +150,7 @@ Next, configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lam
143150
aspect 'software.amazon.lambda:powertools-logging:{{ powertools.version }}'
144151
aspect 'software.amazon.lambda:powertools-tracing:{{ powertools.version }}'
145152
aspect 'software.amazon.lambda:powertools-metrics:{{ powertools.version }}'
153+
implementation "org.aspectj:aspectjrt:1.9.8.RC3"
146154
}
147155
148156
sourceCompatibility = 11
@@ -159,6 +167,12 @@ Next, configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lam
159167
id 'io.freefair.aspectj.post-compile-weaving' version '6.6.3'
160168
}
161169
170+
// the freefair aspect plugins targets gradle 7.6.1
171+
// https://docs.freefair.io/gradle-plugins/6.6.3/reference/
172+
wrapper {
173+
gradleVersion = "7.6.1"
174+
}
175+
162176
repositories {
163177
mavenCentral()
164178
}

docs/index.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,17 @@ Depending on your version of Java (either Java 1.8 or 11+), the configuration sl
211211
=== "Gradle Java 11+"
212212

213213
```groovy
214+
214215
plugins {
215216
id 'java'
216-
id 'io.freefair.aspectj.post-compile-weaving' version '8.1.0'
217+
id 'io.freefair.aspectj.post-compile-weaving' version '8.2.2'
217218
}
219+
220+
// the freefair aspect plugins targets gradle 8.2.1
221+
// https://docs.freefair.io/gradle-plugins/8.2.2/reference/
222+
wrapper {
223+
gradleVersion = "8.2.1"
224+
}
218225
219226
repositories {
220227
mavenCentral()
@@ -233,10 +240,18 @@ Depending on your version of Java (either Java 1.8 or 11+), the configuration sl
233240
=== "Gradle Java 1.8"
234241

235242
```groovy
243+
236244
plugins {
237245
id 'java'
238246
id 'io.freefair.aspectj.post-compile-weaving' version '6.6.3'
239247
}
248+
249+
// the freefair aspect plugins targets gradle 7.6.1
250+
// https://docs.freefair.io/gradle-plugins/6.6.3/reference/
251+
wrapper {
252+
gradleVersion = "7.6.1"
253+
}
254+
240255
241256
repositories {
242257
mavenCentral()

examples/powertools-examples-core/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ This project demonstrates the Lambda for Powertools Java module - including
66
[metrics](https://docs.powertools.aws.dev/lambda/java/core/metrics/).
77

88
We provide examples for the following infrastructure-as-code tools:
9+
910
* [AWS SAM](sam/)
1011
* [AWS CDK](cdk/)
1112

13+
We also provide an example showing the integration of SAM, Powertools, and Gradle:
14+
15+
* [AWS SAM with a Gradle build](gradle/)
16+
1217
For each of the tools, the example application is the same, and consists of the following files:
1318

1419
- [App.java](sam/src/main/java/helloworld/App.java) - Code for the application's Lambda function.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Powertools for AWS Lambda (Java) - Core Utilities Example with Gradle
2+
3+
This project demonstrates the Lambda for Powertools Java module deployed using [Serverless Application Model](https://aws.amazon.com/serverless/sam/) with
4+
[Gradle](https://gradle.org/) running the build. This example is configured for Java 1.8 only; in order to use a newer version, check out the Gradle
5+
configuration guide [in the main project README](../../../README.md).
6+
7+
You can also use `sam init` to create a new Gradle-powered Powertools application - choose to use the **AWS Quick Start Templates**,
8+
and then **Hello World Example with Powertools for AWS Lambda**, **Java 17** runtime, and finally **gradle**.
9+
10+
11+
For general information on the deployed example itself, you can refer to the parent [README](../README.md)
12+
13+
## Configuration
14+
SAM uses [template.yaml](template.yaml) to define the application's AWS resources.
15+
This file defines the Lambda function to be deployed as well as API Gateway for it.
16+
17+
The build of the project is managed by Gradle, and configured in [build.gradle](build.gradle).
18+
19+
## Deploy the sample application
20+
To get started, you can use the Gradle wrapper to bootstrap Gradle and run the build:
21+
22+
```bash
23+
./gradlew build
24+
```
25+
26+
Once this is done to deploy the example, check out the instructions for getting started with SAM in
27+
[the examples directory](../../README.md)
28+
29+
## Additional notes
30+
31+
You can watch the trace information or log information using the SAM CLI:
32+
```bash
33+
# Tail the logs
34+
sam logs --tail $MY_STACK
35+
36+
# Tail the traces
37+
sam traces --tail
38+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
plugins {
3+
id 'java'
4+
id "io.freefair.aspectj.post-compile-weaving" version "6.6.3"
5+
}
6+
7+
wrapper {
8+
gradleVersion = "7.6.1"
9+
}
10+
11+
compileJava {
12+
sourceCompatibility = "1.8"
13+
targetCompatibility = "1.8"
14+
15+
ajc {
16+
enabled = true
17+
}
18+
}
19+
20+
repositories {
21+
mavenCentral()
22+
}
23+
24+
dependencies {
25+
implementation 'com.amazonaws:aws-lambda-java-core:1.2.2'
26+
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.2'
27+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.2.2'
28+
implementation 'com.amazonaws:aws-lambda-java-events:3.11.0'
29+
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.2'
30+
aspect 'software.amazon.lambda:powertools-tracing:1.17.0'
31+
aspect 'software.amazon.lambda:powertools-logging:1.17.0'
32+
aspect 'software.amazon.lambda:powertools-metrics:1.17.0'
33+
testImplementation 'junit:junit:4.13.2'
34+
}
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"body": "{\"message\": \"hello world\"}",
3+
"resource": "/{proxy+}",
4+
"path": "/path/to/resource",
5+
"httpMethod": "POST",
6+
"isBase64Encoded": false,
7+
"queryStringParameters": {
8+
"foo": "bar"
9+
},
10+
"pathParameters": {
11+
"proxy": "/path/to/resource"
12+
},
13+
"stageVariables": {
14+
"baz": "qux"
15+
},
16+
"headers": {
17+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
18+
"Accept-Encoding": "gzip, deflate, sdch",
19+
"Accept-Language": "en-US,en;q=0.8",
20+
"Cache-Control": "max-age=0",
21+
"CloudFront-Forwarded-Proto": "https",
22+
"CloudFront-Is-Desktop-Viewer": "true",
23+
"CloudFront-Is-Mobile-Viewer": "false",
24+
"CloudFront-Is-SmartTV-Viewer": "false",
25+
"CloudFront-Is-Tablet-Viewer": "false",
26+
"CloudFront-Viewer-Country": "US",
27+
"Host": "1234567890.execute-api.us-east-1.amazonaws.com",
28+
"Upgrade-Insecure-Requests": "1",
29+
"User-Agent": "Custom User Agent String",
30+
"Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)",
31+
"X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==",
32+
"X-Forwarded-For": "127.0.0.1, 127.0.0.2",
33+
"X-Forwarded-Port": "443",
34+
"X-Forwarded-Proto": "https"
35+
},
36+
"requestContext": {
37+
"accountId": "123456789012",
38+
"resourceId": "123456",
39+
"stage": "prod",
40+
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
41+
"requestTime": "09/Apr/2015:12:34:56 +0000",
42+
"requestTimeEpoch": 1428582896000,
43+
"identity": {
44+
"cognitoIdentityPoolId": null,
45+
"accountId": null,
46+
"cognitoIdentityId": null,
47+
"caller": null,
48+
"accessKey": null,
49+
"sourceIp": "127.0.0.1",
50+
"cognitoAuthenticationType": null,
51+
"cognitoAuthenticationProvider": null,
52+
"userArn": null,
53+
"userAgent": "Custom User Agent String",
54+
"user": null
55+
},
56+
"path": "/prod/path/to/resource",
57+
"resourcePath": "/{proxy+}",
58+
"httpMethod": "POST",
59+
"apiId": "1234567890",
60+
"protocol": "HTTP/1.1"
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
!gradle-wrapper.jar
2+
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)