Skip to content

docs: Update gradle configuration readme #1359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ jobs:
cache: 'maven'
- name: Build with Maven
run: mvn -B install --file pom.xml
- name: Build Gradle Example
if: ${{ matrix.java == '8' }} # Gradle example can only be built on Java 8
run: |
cd examples/powertools-examples-core/gradle
./gradlew build
- name: Upload coverage to Codecov
uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # 3.1.1
if: ${{ matrix.java == '11' }} # publish results once
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,5 @@ example/HelloWorldFunction/.gradle
example/HelloWorldFunction/build
/example/.gradle/
/example/.java-version
.gradle
build/
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,18 @@ Next, configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lam
<summary><b>Gradle - Java 11+</b></summary>

```groovy

plugins {
id 'java'
id 'io.freefair.aspectj.post-compile-weaving' version '8.1.0'
id 'io.freefair.aspectj.post-compile-weaving' version '8.2.2'
}

// the freefair aspect plugins targets gradle 8.2.1
// https://docs.freefair.io/gradle-plugins/8.2.2/reference/
wrapper {
gradleVersion = "8.2.1"
}

repositories {
mavenCentral()
}
Expand All @@ -143,6 +150,7 @@ Next, configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lam
aspect 'software.amazon.lambda:powertools-logging:{{ powertools.version }}'
aspect 'software.amazon.lambda:powertools-tracing:{{ powertools.version }}'
aspect 'software.amazon.lambda:powertools-metrics:{{ powertools.version }}'
implementation "org.aspectj:aspectjrt:1.9.8.RC3"
}

sourceCompatibility = 11
Expand All @@ -159,6 +167,12 @@ Next, configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lam
id 'io.freefair.aspectj.post-compile-weaving' version '6.6.3'
}

// the freefair aspect plugins targets gradle 7.6.1
// https://docs.freefair.io/gradle-plugins/6.6.3/reference/
wrapper {
gradleVersion = "7.6.1"
}

repositories {
mavenCentral()
}
Expand Down
15 changes: 15 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,17 @@ Depending on your version of Java (either Java 1.8 or 11+), the configuration sl
=== "Gradle Java 11+"

```groovy

plugins {
id 'java'
id 'io.freefair.aspectj.post-compile-weaving' version '8.1.0'
}

// the freefair aspect plugins targets gradle 8.2.1
// https://docs.freefair.io/gradle-plugins/8.2.2/reference/
wrapper {
gradleVersion = "8.2.1"
}

repositories {
mavenCentral()
Expand All @@ -233,10 +240,18 @@ Depending on your version of Java (either Java 1.8 or 11+), the configuration sl
=== "Gradle Java 1.8"

```groovy

plugins {
id 'java'
id 'io.freefair.aspectj.post-compile-weaving' version '6.6.3'
}

// the freefair aspect plugins targets gradle 7.6.1
// https://docs.freefair.io/gradle-plugins/6.6.3/reference/
wrapper {
gradleVersion = "7.6.1"
}


repositories {
mavenCentral()
Expand Down
5 changes: 5 additions & 0 deletions examples/powertools-examples-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ This project demonstrates the Lambda for Powertools Java module - including
[metrics](https://docs.powertools.aws.dev/lambda/java/core/metrics/).

We provide examples for the following infrastructure-as-code tools:

* [AWS SAM](sam/)
* [AWS CDK](cdk/)

We also provide an example showing the integration of SAM, Powertools, and Gradle:

* [AWS SAM with a Gradle build](gradle/)

For each of the tools, the example application is the same, and consists of the following files:

- [App.java](sam/src/main/java/helloworld/App.java) - Code for the application's Lambda function.
Expand Down
34 changes: 34 additions & 0 deletions examples/powertools-examples-core/gradle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Powertools for AWS Lambda (Java) - Core Utilities Example with Gradle

This project demonstrates the Lambda for Powertools Java module deployed using [Serverless Application Model](https://aws.amazon.com/serverless/sam/) with
[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
configuration guide [in the main project README](../../../README.md).

For general information on the deployed example itself, you can refer to the parent [README](../README.md)

## Configuration
SAM uses [template.yaml](template.yaml) to define the application's AWS resources.
This file defines the Lambda function to be deployed as well as API Gateway for it.

The build of the project is managed by Gradle, and configured in [build.gradle](build.gradle).

## Deploy the sample application
To get started, you can use the Gradle wrapper to bootstrap Gradle and run the build:

```bash
./gradlew build
```

Once this is done to deploy the example, check out the instructions for getting started with SAM in
[the examples directory](../../README.md)

## Additional notes

You can watch the trace information or log information using the SAM CLI:
```bash
# Tail the logs
sam logs --tail $MY_STACK

# Tail the traces
sam traces --tail
```
35 changes: 35 additions & 0 deletions examples/powertools-examples-core/gradle/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

plugins {
id 'java'
id "io.freefair.aspectj.post-compile-weaving" version "6.6.3"
}

wrapper {
gradleVersion = "7.6.1"
}

compileJava {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"

ajc {
enabled = true
}
}

repositories {
mavenCentral()
}

dependencies {
implementation 'com.amazonaws:aws-lambda-java-core:1.2.2'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.2.2'
implementation 'com.amazonaws:aws-lambda-java-events:3.11.0'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.2'
aspect 'software.amazon.lambda:powertools-tracing:1.16.1'
aspect 'software.amazon.lambda:powertools-logging:1.16.1'
aspect 'software.amazon.lambda:powertools-metrics:1.16.1'
testImplementation 'junit:junit:4.13.2'
}

62 changes: 62 additions & 0 deletions examples/powertools-examples-core/gradle/events/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"body": "{\"message\": \"hello world\"}",
"resource": "/{proxy+}",
"path": "/path/to/resource",
"httpMethod": "POST",
"isBase64Encoded": false,
"queryStringParameters": {
"foo": "bar"
},
"pathParameters": {
"proxy": "/path/to/resource"
},
"stageVariables": {
"baz": "qux"
},
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, sdch",
"Accept-Language": "en-US,en;q=0.8",
"Cache-Control": "max-age=0",
"CloudFront-Forwarded-Proto": "https",
"CloudFront-Is-Desktop-Viewer": "true",
"CloudFront-Is-Mobile-Viewer": "false",
"CloudFront-Is-SmartTV-Viewer": "false",
"CloudFront-Is-Tablet-Viewer": "false",
"CloudFront-Viewer-Country": "US",
"Host": "1234567890.execute-api.us-east-1.amazonaws.com",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Custom User Agent String",
"Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)",
"X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==",
"X-Forwarded-For": "127.0.0.1, 127.0.0.2",
"X-Forwarded-Port": "443",
"X-Forwarded-Proto": "https"
},
"requestContext": {
"accountId": "123456789012",
"resourceId": "123456",
"stage": "prod",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
"requestTime": "09/Apr/2015:12:34:56 +0000",
"requestTimeEpoch": 1428582896000,
"identity": {
"cognitoIdentityPoolId": null,
"accountId": null,
"cognitoIdentityId": null,
"caller": null,
"accessKey": null,
"sourceIp": "127.0.0.1",
"cognitoAuthenticationType": null,
"cognitoAuthenticationProvider": null,
"userArn": null,
"userAgent": "Custom User Agent String",
"user": null
},
"path": "/prod/path/to/resource",
"resourcePath": "/{proxy+}",
"httpMethod": "POST",
"apiId": "1234567890",
"protocol": "HTTP/1.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!gradle-wrapper.jar

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading