From c46ba2d2eb105e832276ada0cdbb8a07fa3aa72a Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Thu, 16 Nov 2023 23:29:42 +0100 Subject: [PATCH 1/9] e2e tests with java 21 --- .../lambda/powertools/testutils/Infrastructure.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java index 11ee24b05..8d44da472 100644 --- a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java +++ b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java @@ -114,7 +114,6 @@ public class Infrastructure { private final String queue; private final String kinesisStream; private final String largeMessagesBucket; - private final JavaRuntime lambdaRuntimeVersion; private String ddbStreamsTableName; private String functionName; private Object cfnTemplate; @@ -125,7 +124,6 @@ private Infrastructure(Builder builder) { this.tracing = builder.tracing; this.envVar = builder.environmentVariables; this.runtime = builder.runtime; - this.lambdaRuntimeVersion = builder.lambdaRuntimeVersion; this.timeout = builder.timeoutInSeconds; this.pathToFunction = builder.pathToFunction; this.idempotencyTable = builder.idemPotencyTable; @@ -206,7 +204,6 @@ public void destroy() { private Stack createStackWithLambda() { boolean createTableForAsyncTests = false; Stack stack = new Stack(app, stackName); - List packagingInstruction = Arrays.asList( "/bin/sh", "-c", @@ -250,7 +247,7 @@ private Stack createStackWithLambda() { .handler("software.amazon.lambda.powertools.e2e.Function::handleRequest") .memorySize(1024) .timeout(Duration.seconds(timeout)) - .runtime(lambdaRuntimeVersion.getCdkRuntime()) + .runtime(runtime.getCdkRuntime()) .environment(envVar) .tracing(tracing ? Tracing.ACTIVE : Tracing.DISABLED) .build(); @@ -507,11 +504,9 @@ public static class Builder { private String queue; private String kinesisStream; private String ddbStreamsTableName; - private JavaRuntime lambdaRuntimeVersion; private Builder() { runtime = mapRuntimeVersion("JAVA_VERSION"); - lambdaRuntimeVersion = mapRuntimeVersion("JAVA_LAMBDA_RUNTIME_VERSION"); } @@ -520,7 +515,7 @@ private JavaRuntime mapRuntimeVersion(String environmentVariableName) { String javaVersion = System.getenv(environmentVariableName); // must be set in GitHub actions JavaRuntime ret = null; if (javaVersion == null) { - throw new IllegalArgumentException("JAVA_LAMBDA_RUNTIME_VERSION is not set"); + throw new IllegalArgumentException("JAVA_VERSION is not set"); } if (javaVersion.startsWith("8")) { ret = JavaRuntime.JAVA8AL2; From b54d61c2fc76f2b9c6fb3950b182af104286c441 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Fri, 17 Nov 2023 13:00:41 +0100 Subject: [PATCH 2/9] use aspectj 1.9.21-SNAPSHOT --- pom.xml | 30 +++- powertools-e2e-tests/handlers/logging/pom.xml | 4 + powertools-e2e-tests/handlers/pom.xml | 140 ++++++++---------- 3 files changed, 97 insertions(+), 77 deletions(-) diff --git a/pom.xml b/pom.xml index 0ac62cbda..77c26a3fb 100644 --- a/pom.xml +++ b/pom.xml @@ -75,7 +75,6 @@ 1.8 2.20.0 2.15.3 - 1.9.7 2.21.0 2.14.0 2.1.3 @@ -516,6 +515,35 @@ + + + + aspectj197 + + [1.8,16] + + + 1.9.7 + + + + aspectj1920 + + [17,20] + + + 1.9.20.1 + + + + aspectj1921 + + [21,) + + + 1.9.21-SNAPSHOT + + jdk16 diff --git a/powertools-e2e-tests/handlers/logging/pom.xml b/powertools-e2e-tests/handlers/logging/pom.xml index 4b613f2bf..61ec6b414 100644 --- a/powertools-e2e-tests/handlers/logging/pom.xml +++ b/powertools-e2e-tests/handlers/logging/pom.xml @@ -17,6 +17,10 @@ software.amazon.lambda powertools-logging + + org.aspectj + aspectjrt + com.amazonaws aws-lambda-java-events diff --git a/powertools-e2e-tests/handlers/pom.xml b/powertools-e2e-tests/handlers/pom.xml index 502b14eb3..1004d9dae 100644 --- a/powertools-e2e-tests/handlers/pom.xml +++ b/powertools-e2e-tests/handlers/pom.xml @@ -42,7 +42,11 @@ pom import - + + org.aspectj + aspectjrt + ${aspectj.version} + software.amazon.lambda powertools-logging @@ -143,97 +147,81 @@ false + + dev.aspectj + aspectj-maven-plugin + ${aspectj.plugin.version} + + true + ${maven.compiler.source} + ${maven.compiler.target} + ${maven.compiler.target} + ignore + ${project.build.sourceEncoding} + + + + + compile + test-compile + + + + + + org.aspectj + aspectjtools + ${aspectj.version} + + + + - jdk8 + jdk8to16 - (,11) + [1.8,16] 1.9.7 - - - - org.aspectj - aspectjtools - ${aspectj.version} - - - - - - - - dev.aspectj - aspectj-maven-plugin - ${aspectj.plugin.version} - - ${maven.compiler.source} - ${maven.compiler.target} - ${maven.compiler.target} - ignore - ${project.build.sourceEncoding} - - - - process-sources - - compile - test-compile - - - - - - - org.aspectj - aspectjtools - ${aspectj.version} - - - - - - - jdk11plus + jdk17to20 - [11,) + [17,20] - - - - - dev.aspectj - aspectj-maven-plugin - ${aspectj.plugin.version} - - ${maven.compiler.source} - ${maven.compiler.target} - ${maven.compiler.target} - ignore - ${project.build.sourceEncoding} - - - - process-sources - - compile - test-compile - - - - - - - + + 1.9.20.1 + + + + jdk21 + + [21,) + + + 1.9.21-SNAPSHOT + + + + ossrh-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + always + + + + From 146b6a837db372a97360442d03183716f63f1429 Mon Sep 17 00:00:00 2001 From: Scott Gerring Date: Fri, 17 Nov 2023 17:07:43 +0100 Subject: [PATCH 3/9] Fix log4j2.xml missing in logging test for java21 --- .../amazon/lambda/powertools/testutils/Infrastructure.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java index 8d44da472..87f22b717 100644 --- a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java +++ b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java @@ -210,7 +210,7 @@ private Stack createStackWithLambda() { "cd " + pathToFunction + " && timeout -s SIGKILL 5m mvn clean install -ff " + " -Dmaven.test.skip=true " + - " -Dmaven.resources.skip=true " + + //" -Dmaven.resources.skip=true " + " -Dmaven.compiler.source=" + runtime.getMvnProperty() + " -Dmaven.compiler.target=" + runtime.getMvnProperty() + " && cp /asset-input/" + pathToFunction + "/target/function.jar /asset-output/" From 38082c33fd2c45f47b55cdbb16e1518f1cb285a0 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Fri, 17 Nov 2023 22:21:25 +0100 Subject: [PATCH 4/9] rollback double runtime --- pom.xml | 14 ++++++++++++++ .../powertools/testutils/Infrastructure.java | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 77c26a3fb..b07a36323 100644 --- a/pom.xml +++ b/pom.xml @@ -102,6 +102,20 @@ + + + ossrh-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + always + + + + diff --git a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java index 87f22b717..36c055533 100644 --- a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java +++ b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java @@ -204,6 +204,7 @@ public void destroy() { private Stack createStackWithLambda() { boolean createTableForAsyncTests = false; Stack stack = new Stack(app, stackName); + List packagingInstruction = Arrays.asList( "/bin/sh", "-c", @@ -515,7 +516,7 @@ private JavaRuntime mapRuntimeVersion(String environmentVariableName) { String javaVersion = System.getenv(environmentVariableName); // must be set in GitHub actions JavaRuntime ret = null; if (javaVersion == null) { - throw new IllegalArgumentException("JAVA_VERSION is not set"); + throw new IllegalArgumentException(environmentVariableName + " is not set"); } if (javaVersion.startsWith("8")) { ret = JavaRuntime.JAVA8AL2; From 4be508d4d610cce537478f69a1b446959354e8e8 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Fri, 17 Nov 2023 22:24:43 +0100 Subject: [PATCH 5/9] remove comment --- .../amazon/lambda/powertools/testutils/Infrastructure.java | 1 - 1 file changed, 1 deletion(-) diff --git a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java index 36c055533..28a0f2bb4 100644 --- a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java +++ b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java @@ -211,7 +211,6 @@ private Stack createStackWithLambda() { "cd " + pathToFunction + " && timeout -s SIGKILL 5m mvn clean install -ff " + " -Dmaven.test.skip=true " + - //" -Dmaven.resources.skip=true " + " -Dmaven.compiler.source=" + runtime.getMvnProperty() + " -Dmaven.compiler.target=" + runtime.getMvnProperty() + " && cp /asset-input/" + pathToFunction + "/target/function.jar /asset-output/" From 24b49a82e49dcd88bc83c7bb390cb58d77a05e93 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Fri, 17 Nov 2023 23:25:33 +0100 Subject: [PATCH 6/9] keep aspectj 1.9.7 in parent for java8 compatibility --- pom.xml | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/pom.xml b/pom.xml index b07a36323..dcf62d473 100644 --- a/pom.xml +++ b/pom.xml @@ -83,6 +83,7 @@ 3.11.3 1.1.2 3.11.0 + 1.9.7 1.13.1 3.1.2 0.8.10 @@ -530,34 +531,6 @@ - - - aspectj197 - - [1.8,16] - - - 1.9.7 - - - - aspectj1920 - - [17,20] - - - 1.9.20.1 - - - - aspectj1921 - - [21,) - - - 1.9.21-SNAPSHOT - - jdk16 From 41d7ef3cfb7a555f0913bb4f7968e44c225609ac Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Sun, 19 Nov 2023 23:00:43 +0100 Subject: [PATCH 7/9] use M1 instead of snapshot --- pom.xml | 14 -------------- powertools-e2e-tests/handlers/pom.xml | 16 +--------------- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/pom.xml b/pom.xml index dcf62d473..3c30dc260 100644 --- a/pom.xml +++ b/pom.xml @@ -103,20 +103,6 @@ - - - ossrh-snapshots - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - always - - - - diff --git a/powertools-e2e-tests/handlers/pom.xml b/powertools-e2e-tests/handlers/pom.xml index 1004d9dae..a9096477b 100644 --- a/powertools-e2e-tests/handlers/pom.xml +++ b/powertools-e2e-tests/handlers/pom.xml @@ -205,23 +205,9 @@ [21,) - 1.9.21-SNAPSHOT + 1.9.21.M1 - - - ossrh-snapshots - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - always - - - - From a215ff788745a78203048f283bb01a0a1ff3f368 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Mon, 20 Nov 2023 08:59:28 +0100 Subject: [PATCH 8/9] update documentation for aspectj --- README.md | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index bdf779bfb..c24ae4d74 100644 --- a/README.md +++ b/README.md @@ -9,14 +9,6 @@ Powertools for AWS Lambda (Java) is a developer toolkit to implement Serverless **[📜Documentation](https://docs.powertools.aws.dev/lambda-java/)** | **[Feature request](https://github.com/aws-powertools/powertools-lambda-java/issues/new?assignees=&labels=feature-request%2C+triage&template=feature_request.md&title=)** | **[🐛Bug Report](https://github.com/aws-powertools/powertools-lambda-java/issues/new?assignees=&labels=bug%2C+triage&template=bug_report.md&title=)** | **[Detailed blog post](https://aws.amazon.com/blogs/opensource/simplifying-serverless-best-practices-with-aws-lambda-powertools-java/)** -### Java Compatibility -Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the -[corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). - -AspectJ does not yet support Java 21 [[1]](https://github.com/eclipse-aspectj/aspectj/issues/260), [[2]](https://github.com/eclipse-aspectj/aspectj/blob/master/docs/dist/doc/JavaVersionCompatibility.md). -If you need to use aspects - either Powertools features leveraging aspects or other libraries - you should use the JDK 17 compiler and target either the Java 17 or Java 21 -Lambda runtimes. - ### Installation Powertools for AWS Lambda (Java) is available in Maven Central. You can use your favourite dependency management tool to install it @@ -196,6 +188,39 @@ Next, configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lam ``` +#### Java Compatibility +Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the +[corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). + +For the following modules, Powertools for AWS Lambda (Java) leverages the **aspectj** library to provide annotations: +- Logging +- Metrics +- Tracing +- Parameters +- Idempotency +- Validation +- Large messages + +It's important to notice the [dependency matrix](https://github.com/eclipse-aspectj/aspectj/blob/master/docs/dist/doc/JavaVersionCompatibility.md) between this library and the JDK: + +| JDK version | aspectj version | +|-------------|-----------------| +| `1.8` | `1.9.7` | +| `11-17` | `1.9.20.1` | +| `21` | `1.9.21` | + +_Note: 1.9.21 is not yet available and Java 21 not yet officialy supported by aspectj, but you can already use the `1.9.21.M1`_ + +You may need to add the good version of `aspectjrt` to your dependencies based on the jdk used for building your function: + +```xml + + org.aspectj + aspectjrt + 1.9.?? + +``` + ## Examples See the latest release of the **[examples](https://github.com/aws-powertools/powertools-lambda-java/tree/v1.18.0/examples)** for example projects showcasing usage of different utilities. From ce4ed7f2cb9b81f6eba6ebf48249528066060255 Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Mon, 20 Nov 2023 09:15:43 +0100 Subject: [PATCH 9/9] update documentation for aspectj --- README.md | 38 ++++++++++++++++---------------------- docs/index.md | 43 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index c24ae4d74..dbe8eb2fe 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ Powertools for AWS Lambda (Java) is a developer toolkit to implement Serverless **[📜Documentation](https://docs.powertools.aws.dev/lambda-java/)** | **[Feature request](https://github.com/aws-powertools/powertools-lambda-java/issues/new?assignees=&labels=feature-request%2C+triage&template=feature_request.md&title=)** | **[🐛Bug Report](https://github.com/aws-powertools/powertools-lambda-java/issues/new?assignees=&labels=bug%2C+triage&template=bug_report.md&title=)** | **[Detailed blog post](https://aws.amazon.com/blogs/opensource/simplifying-serverless-best-practices-with-aws-lambda-powertools-java/)** -### Installation +## Installation Powertools for AWS Lambda (Java) is available in Maven Central. You can use your favourite dependency management tool to install it -#### Maven: +### Maven: ```xml ... @@ -188,20 +188,22 @@ Next, configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lam ``` -#### Java Compatibility +### Java Compatibility Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the [corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). +For the modules that provide annotations, Powertools for AWS Lambda (Java) leverages the **aspectj** library. +You may need to add the good version of `aspectjrt` to your dependencies based on the JDK used for building your function: -For the following modules, Powertools for AWS Lambda (Java) leverages the **aspectj** library to provide annotations: -- Logging -- Metrics -- Tracing -- Parameters -- Idempotency -- Validation -- Large messages +```xml + + org.aspectj + aspectjrt + 1.9.?? + +``` -It's important to notice the [dependency matrix](https://github.com/eclipse-aspectj/aspectj/blob/master/docs/dist/doc/JavaVersionCompatibility.md) between this library and the JDK: +
+ JDK - aspectj dependency matrix | JDK version | aspectj version | |-------------|-----------------| @@ -209,17 +211,9 @@ It's important to notice the [dependency matrix](https://github.com/eclipse-aspe | `11-17` | `1.9.20.1` | | `21` | `1.9.21` | -_Note: 1.9.21 is not yet available and Java 21 not yet officialy supported by aspectj, but you can already use the `1.9.21.M1`_ - -You may need to add the good version of `aspectjrt` to your dependencies based on the jdk used for building your function: +More info [here](https://github.com/aws-powertools/powertools-lambda-java/pull/1519/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R191). -```xml - - org.aspectj - aspectjrt - 1.9.?? - -``` +
## Examples diff --git a/docs/index.md b/docs/index.md index b1b55e2d6..884e02476 100644 --- a/docs/index.md +++ b/docs/index.md @@ -15,14 +15,6 @@ Powertools for AWS Lambda (Java) is a suite of utilities for AWS Lambda Function Check out [this detailed blog post](https://aws.amazon.com/blogs/opensource/simplifying-serverless-best-practices-with-aws-lambda-powertools-java/) with a practical example. To dive deeper, the [Powertools for AWS Lambda (Java) workshop](https://catalog.us-east-1.prod.workshops.aws/workshops/a7011c82-e4af-4a52-80fa-fcd61f1dacd9/en-US/introduction) is a great next step. -???+ tip "Java Compatability" - Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the - [corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). - - AspectJ does not yet support Java 21 [[1]](https://github.com/eclipse-aspectj/aspectj/issues/260), [[2]](https://github.com/eclipse-aspectj/aspectj/blob/master/docs/dist/doc/JavaVersionCompatibility.md). - If you need to use aspects - either Powertools features leveraging aspects or other libraries - you should use the JDK 17 compiler and target either the Java 17 or Java 21 - Lambda runtimes. - ## Tenets This project separates core utilities that will be available in other runtimes vs general utilities that might not be available across all runtimes. @@ -282,6 +274,41 @@ Depending on your version of Java (either Java 1.8 or 11+), the configuration sl Under the hood, `org.codehaus.mojo:aspectj-maven-plugin` is based on AspectJ 1.9.7, while `dev.aspectj:aspectj-maven-plugin` is based on AspectJ 1.9.8, compiled for Java 11+. +### Java Compatibility +Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the +[corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). + +For the following modules, Powertools for AWS Lambda (Java) leverages the **aspectj** library to provide annotations: +- Logging +- Metrics +- Tracing +- Parameters +- Idempotency +- Validation +- Large messages + + +You may need to add the good version of `aspectjrt` to your dependencies based on the jdk used for building your function: + +```xml + + org.aspectj + aspectjrt + 1.9.?? + +``` + +Use the following [dependency matrix](https://github.com/eclipse-aspectj/aspectj/blob/master/docs/dist/doc/JavaVersionCompatibility.md) between this library and the JDK: + +| JDK version | aspectj version | +|-------------|-----------------| +| `1.8` | `1.9.7` | +| `11-17` | `1.9.20.1` | +| `21` | `1.9.21` | + +_Note: 1.9.21 is not yet available and Java 21 not yet officially supported by aspectj, but you can already use the `1.9.21.M1`_ + + ## Environment variables !!! info