Skip to content
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

chore: Testing java21 aspectj pre-release #1519

Merged
merged 9 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 29 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +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/)**

### 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
## 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
<dependencies>
...
Expand Down Expand Up @@ -196,6 +188,33 @@ Next, configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lam
```
</details>

### 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:

```xml
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.??</version>
</dependency>
```

<details>
<summary><b>JDK - aspectj dependency matrix</b></summary>

| JDK version | aspectj version |
|-------------|-----------------|
| `1.8` | `1.9.7` |
| `11-17` | `1.9.20.1` |
| `21` | `1.9.21` |

More info [here](https://github.com/aws-powertools/powertools-lambda-java/pull/1519/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R191).

</details>

## 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.
Expand Down
43 changes: 35 additions & 8 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.??</version>
</dependency>
```

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
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
<maven.compiler.target>1.8</maven.compiler.target>
<log4j.version>2.20.0</log4j.version>
<jackson.version>2.15.3</jackson.version>
<aspectj.version>1.9.7</aspectj.version>
<aws.sdk.version>2.21.0</aws.sdk.version>
<aws.xray.recorder.version>2.14.0</aws.xray.recorder.version>
<payloadoffloading-common.version>2.1.3</payloadoffloading-common.version>
Expand All @@ -84,6 +83,7 @@
<lambda.events.version>3.11.3</lambda.events.version>
<lambda.serial.version>1.1.2</lambda.serial.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<aspectj.version>1.9.7</aspectj.version>
<aspectj-maven-plugin.version>1.13.1</aspectj-maven-plugin.version>
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
<jacoco-maven-plugin.version>0.8.10</jacoco-maven-plugin.version>
Expand Down Expand Up @@ -516,6 +516,7 @@
</plugins>
</build>
</profile>

<profile>
<id>jdk16</id>
<activation>
Expand Down
4 changes: 4 additions & 0 deletions powertools-e2e-tests/handlers/logging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-logging</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
Expand Down
126 changes: 50 additions & 76 deletions powertools-e2e-tests/handlers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>software.amazon.lambda</groupId>
<artifactId>powertools-logging</artifactId>
Expand Down Expand Up @@ -143,96 +147,66 @@
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>dev.aspectj</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>${aspectj.plugin.version}</version>
<configuration>
<verbose>true</verbose>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<complianceLevel>${maven.compiler.target}</complianceLevel>
<Xlint>ignore</Xlint>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<!-- https://github.com/eclipse-aspectj/aspectj/blob/master/docs/dist/doc/JavaVersionCompatibility.md -->
<profile>
<id>jdk8</id>
<id>jdk8to16</id>
<activation>
<jdk>(,11)</jdk> <!-- < 11 -->
<jdk>[1.8,16]</jdk>
</activation>
<properties>
<aspectj.version>1.9.7</aspectj.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>dev.aspectj</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>${aspectj.plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<complianceLevel>${maven.compiler.target}</complianceLevel>
<Xlint>ignore</Xlint>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<!-- Enforce aspectJ 1.9.7 -->
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profile>
<id>jdk11plus</id>
<id>jdk17to20</id>
<activation>
<jdk>[11,)</jdk> <!-- >= 11 -->
<jdk>[17,20]</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>dev.aspectj</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>${aspectj.plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<complianceLevel>${maven.compiler.target}</complianceLevel>
<Xlint>ignore</Xlint>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<properties>
<aspectj.version>1.9.20.1</aspectj.version>
</properties>
</profile>
<profile>
<id>jdk21</id>
<activation>
<jdk>[21,)</jdk>
</activation>
<properties>
<aspectj.version>1.9.21.M1</aspectj.version>
</properties>
</profile>
</profiles>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -213,7 +211,6 @@ private Stack createStackWithLambda() {
"cd " + pathToFunction +
" && timeout -s SIGKILL 5m mvn clean install -ff " +
" -Dmaven.test.skip=true " +
" -Dmaven.resources.skip=true " +
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷

" -Dmaven.compiler.source=" + runtime.getMvnProperty() +
" -Dmaven.compiler.target=" + runtime.getMvnProperty() +
" && cp /asset-input/" + pathToFunction + "/target/function.jar /asset-output/"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
}


Expand All @@ -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(environmentVariableName + " is not set");
}
if (javaVersion.startsWith("8")) {
ret = JavaRuntime.JAVA8AL2;
Expand Down