Skip to content

Commit 8e4173a

Browse files
chore: Testing java21 aspectj pre-release (#1519)
* e2e tests with java 21 * use aspectj 1.9.21-SNAPSHOT * Fix log4j2.xml missing in logging test for java21 * rollback double runtime * remove comment * keep aspectj 1.9.7 in parent for java8 compatibility * use M1 instead of snapshot * update documentation for aspectj * update documentation for aspectj --------- Co-authored-by: Jerome Van Der Linden <[email protected]>
1 parent ff4ee68 commit 8e4173a

File tree

6 files changed

+122
-102
lines changed

6 files changed

+122
-102
lines changed

Diff for: README.md

+29-10
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,11 @@ Powertools for AWS Lambda (Java) is a developer toolkit to implement Serverless
99
1010
**[📜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/)**
1111

12-
### Java Compatibility
13-
Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the
14-
[corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).
15-
16-
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).
17-
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
18-
Lambda runtimes.
19-
20-
### Installation
12+
## Installation
2113

2214
Powertools for AWS Lambda (Java) is available in Maven Central. You can use your favourite dependency management tool to install it
2315

24-
#### Maven:
16+
### Maven:
2517
```xml
2618
<dependencies>
2719
...
@@ -196,6 +188,33 @@ Next, configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lam
196188
```
197189
</details>
198190

191+
### Java Compatibility
192+
Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the
193+
[corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).
194+
For the modules that provide annotations, Powertools for AWS Lambda (Java) leverages the **aspectj** library.
195+
You may need to add the good version of `aspectjrt` to your dependencies based on the JDK used for building your function:
196+
197+
```xml
198+
<dependency>
199+
<groupId>org.aspectj</groupId>
200+
<artifactId>aspectjrt</artifactId>
201+
<version>1.9.??</version>
202+
</dependency>
203+
```
204+
205+
<details>
206+
<summary><b>JDK - aspectj dependency matrix</b></summary>
207+
208+
| JDK version | aspectj version |
209+
|-------------|-----------------|
210+
| `1.8` | `1.9.7` |
211+
| `11-17` | `1.9.20.1` |
212+
| `21` | `1.9.21` |
213+
214+
More info [here](https://github.com/aws-powertools/powertools-lambda-java/pull/1519/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R191).
215+
216+
</details>
217+
199218
## Examples
200219

201220
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.

Diff for: docs/index.md

+35-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ Powertools for AWS Lambda (Java) is a suite of utilities for AWS Lambda Function
1515
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,
1616
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.
1717

18-
???+ tip "Java Compatability"
19-
Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the
20-
[corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).
21-
22-
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).
23-
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
24-
Lambda runtimes.
25-
2618
## Tenets
2719

2820
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
282274
Under the hood, `org.codehaus.mojo:aspectj-maven-plugin` is based on AspectJ 1.9.7,
283275
while `dev.aspectj:aspectj-maven-plugin` is based on AspectJ 1.9.8, compiled for Java 11+.
284276

277+
### Java Compatibility
278+
Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the
279+
[corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).
280+
281+
For the following modules, Powertools for AWS Lambda (Java) leverages the **aspectj** library to provide annotations:
282+
- Logging
283+
- Metrics
284+
- Tracing
285+
- Parameters
286+
- Idempotency
287+
- Validation
288+
- Large messages
289+
290+
291+
You may need to add the good version of `aspectjrt` to your dependencies based on the jdk used for building your function:
292+
293+
```xml
294+
<dependency>
295+
<groupId>org.aspectj</groupId>
296+
<artifactId>aspectjrt</artifactId>
297+
<version>1.9.??</version>
298+
</dependency>
299+
```
300+
301+
Use the following [dependency matrix](https://github.com/eclipse-aspectj/aspectj/blob/master/docs/dist/doc/JavaVersionCompatibility.md) between this library and the JDK:
302+
303+
| JDK version | aspectj version |
304+
|-------------|-----------------|
305+
| `1.8` | `1.9.7` |
306+
| `11-17` | `1.9.20.1` |
307+
| `21` | `1.9.21` |
308+
309+
_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`_
310+
311+
285312
## Environment variables
286313

287314
!!! info

Diff for: pom.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
<maven.compiler.target>1.8</maven.compiler.target>
7676
<log4j.version>2.20.0</log4j.version>
7777
<jackson.version>2.15.3</jackson.version>
78-
<aspectj.version>1.9.7</aspectj.version>
7978
<aws.sdk.version>2.21.0</aws.sdk.version>
8079
<aws.xray.recorder.version>2.14.0</aws.xray.recorder.version>
8180
<payloadoffloading-common.version>2.1.3</payloadoffloading-common.version>
@@ -84,6 +83,7 @@
8483
<lambda.events.version>3.11.3</lambda.events.version>
8584
<lambda.serial.version>1.1.2</lambda.serial.version>
8685
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
86+
<aspectj.version>1.9.7</aspectj.version>
8787
<aspectj-maven-plugin.version>1.13.1</aspectj-maven-plugin.version>
8888
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
8989
<jacoco-maven-plugin.version>0.8.10</jacoco-maven-plugin.version>
@@ -516,6 +516,7 @@
516516
</plugins>
517517
</build>
518518
</profile>
519+
519520
<profile>
520521
<id>jdk16</id>
521522
<activation>

Diff for: powertools-e2e-tests/handlers/logging/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<groupId>software.amazon.lambda</groupId>
1818
<artifactId>powertools-logging</artifactId>
1919
</dependency>
20+
<dependency>
21+
<groupId>org.aspectj</groupId>
22+
<artifactId>aspectjrt</artifactId>
23+
</dependency>
2024
<dependency>
2125
<groupId>com.amazonaws</groupId>
2226
<artifactId>aws-lambda-java-events</artifactId>

Diff for: powertools-e2e-tests/handlers/pom.xml

+50-76
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@
4242
<type>pom</type>
4343
<scope>import</scope>
4444
</dependency>
45-
45+
<dependency>
46+
<groupId>org.aspectj</groupId>
47+
<artifactId>aspectjrt</artifactId>
48+
<version>${aspectj.version}</version>
49+
</dependency>
4650
<dependency>
4751
<groupId>software.amazon.lambda</groupId>
4852
<artifactId>powertools-logging</artifactId>
@@ -143,96 +147,66 @@
143147
<useIncrementalCompilation>false</useIncrementalCompilation>
144148
</configuration>
145149
</plugin>
150+
<plugin>
151+
<groupId>dev.aspectj</groupId>
152+
<artifactId>aspectj-maven-plugin</artifactId>
153+
<version>${aspectj.plugin.version}</version>
154+
<configuration>
155+
<verbose>true</verbose>
156+
<source>${maven.compiler.source}</source>
157+
<target>${maven.compiler.target}</target>
158+
<complianceLevel>${maven.compiler.target}</complianceLevel>
159+
<Xlint>ignore</Xlint>
160+
<encoding>${project.build.sourceEncoding}</encoding>
161+
</configuration>
162+
<executions>
163+
<execution>
164+
<goals>
165+
<goal>compile</goal>
166+
<goal>test-compile</goal>
167+
</goals>
168+
</execution>
169+
</executions>
170+
<dependencies>
171+
<dependency>
172+
<groupId>org.aspectj</groupId>
173+
<artifactId>aspectjtools</artifactId>
174+
<version>${aspectj.version}</version>
175+
</dependency>
176+
</dependencies>
177+
</plugin>
146178
</plugins>
147179
</pluginManagement>
148180
</build>
149181

150182
<profiles>
183+
<!-- https://github.com/eclipse-aspectj/aspectj/blob/master/docs/dist/doc/JavaVersionCompatibility.md -->
151184
<profile>
152-
<id>jdk8</id>
185+
<id>jdk8to16</id>
153186
<activation>
154-
<jdk>(,11)</jdk> <!-- < 11 -->
187+
<jdk>[1.8,16]</jdk>
155188
</activation>
156189
<properties>
157190
<aspectj.version>1.9.7</aspectj.version>
158191
</properties>
159-
<dependencyManagement>
160-
<dependencies>
161-
<dependency>
162-
<groupId>org.aspectj</groupId>
163-
<artifactId>aspectjtools</artifactId>
164-
<version>${aspectj.version}</version>
165-
</dependency>
166-
</dependencies>
167-
</dependencyManagement>
168-
<build>
169-
<pluginManagement>
170-
<plugins>
171-
<plugin>
172-
<groupId>dev.aspectj</groupId>
173-
<artifactId>aspectj-maven-plugin</artifactId>
174-
<version>${aspectj.plugin.version}</version>
175-
<configuration>
176-
<source>${maven.compiler.source}</source>
177-
<target>${maven.compiler.target}</target>
178-
<complianceLevel>${maven.compiler.target}</complianceLevel>
179-
<Xlint>ignore</Xlint>
180-
<encoding>${project.build.sourceEncoding}</encoding>
181-
</configuration>
182-
<executions>
183-
<execution>
184-
<phase>process-sources</phase>
185-
<goals>
186-
<goal>compile</goal>
187-
<goal>test-compile</goal>
188-
</goals>
189-
</execution>
190-
</executions>
191-
<!-- Enforce aspectJ 1.9.7 -->
192-
<dependencies>
193-
<dependency>
194-
<groupId>org.aspectj</groupId>
195-
<artifactId>aspectjtools</artifactId>
196-
<version>${aspectj.version}</version>
197-
</dependency>
198-
</dependencies>
199-
</plugin>
200-
</plugins>
201-
</pluginManagement>
202-
</build>
203192
</profile>
204193
<profile>
205-
<id>jdk11plus</id>
194+
<id>jdk17to20</id>
206195
<activation>
207-
<jdk>[11,)</jdk> <!-- >= 11 -->
196+
<jdk>[17,20]</jdk>
208197
</activation>
209-
<build>
210-
<pluginManagement>
211-
<plugins>
212-
<plugin>
213-
<groupId>dev.aspectj</groupId>
214-
<artifactId>aspectj-maven-plugin</artifactId>
215-
<version>${aspectj.plugin.version}</version>
216-
<configuration>
217-
<source>${maven.compiler.source}</source>
218-
<target>${maven.compiler.target}</target>
219-
<complianceLevel>${maven.compiler.target}</complianceLevel>
220-
<Xlint>ignore</Xlint>
221-
<encoding>${project.build.sourceEncoding}</encoding>
222-
</configuration>
223-
<executions>
224-
<execution>
225-
<phase>process-sources</phase>
226-
<goals>
227-
<goal>compile</goal>
228-
<goal>test-compile</goal>
229-
</goals>
230-
</execution>
231-
</executions>
232-
</plugin>
233-
</plugins>
234-
</pluginManagement>
235-
</build>
198+
<properties>
199+
<aspectj.version>1.9.20.1</aspectj.version>
200+
</properties>
201+
</profile>
202+
<profile>
203+
<id>jdk21</id>
204+
<activation>
205+
<jdk>[21,)</jdk>
206+
</activation>
207+
<properties>
208+
<aspectj.version>1.9.21.M1</aspectj.version>
209+
</properties>
236210
</profile>
237211
</profiles>
238212

Diff for: powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ public class Infrastructure {
114114
private final String queue;
115115
private final String kinesisStream;
116116
private final String largeMessagesBucket;
117-
private final JavaRuntime lambdaRuntimeVersion;
118117
private String ddbStreamsTableName;
119118
private String functionName;
120119
private Object cfnTemplate;
@@ -125,7 +124,6 @@ private Infrastructure(Builder builder) {
125124
this.tracing = builder.tracing;
126125
this.envVar = builder.environmentVariables;
127126
this.runtime = builder.runtime;
128-
this.lambdaRuntimeVersion = builder.lambdaRuntimeVersion;
129127
this.timeout = builder.timeoutInSeconds;
130128
this.pathToFunction = builder.pathToFunction;
131129
this.idempotencyTable = builder.idemPotencyTable;
@@ -213,7 +211,6 @@ private Stack createStackWithLambda() {
213211
"cd " + pathToFunction +
214212
" && timeout -s SIGKILL 5m mvn clean install -ff " +
215213
" -Dmaven.test.skip=true " +
216-
" -Dmaven.resources.skip=true " +
217214
" -Dmaven.compiler.source=" + runtime.getMvnProperty() +
218215
" -Dmaven.compiler.target=" + runtime.getMvnProperty() +
219216
" && cp /asset-input/" + pathToFunction + "/target/function.jar /asset-output/"
@@ -250,7 +247,7 @@ private Stack createStackWithLambda() {
250247
.handler("software.amazon.lambda.powertools.e2e.Function::handleRequest")
251248
.memorySize(1024)
252249
.timeout(Duration.seconds(timeout))
253-
.runtime(lambdaRuntimeVersion.getCdkRuntime())
250+
.runtime(runtime.getCdkRuntime())
254251
.environment(envVar)
255252
.tracing(tracing ? Tracing.ACTIVE : Tracing.DISABLED)
256253
.build();
@@ -507,11 +504,9 @@ public static class Builder {
507504
private String queue;
508505
private String kinesisStream;
509506
private String ddbStreamsTableName;
510-
private JavaRuntime lambdaRuntimeVersion;
511507

512508
private Builder() {
513509
runtime = mapRuntimeVersion("JAVA_VERSION");
514-
lambdaRuntimeVersion = mapRuntimeVersion("JAVA_LAMBDA_RUNTIME_VERSION");
515510
}
516511

517512

@@ -520,7 +515,7 @@ private JavaRuntime mapRuntimeVersion(String environmentVariableName) {
520515
String javaVersion = System.getenv(environmentVariableName); // must be set in GitHub actions
521516
JavaRuntime ret = null;
522517
if (javaVersion == null) {
523-
throw new IllegalArgumentException("JAVA_LAMBDA_RUNTIME_VERSION is not set");
518+
throw new IllegalArgumentException(environmentVariableName + " is not set");
524519
}
525520
if (javaVersion.startsWith("8")) {
526521
ret = JavaRuntime.JAVA8AL2;

0 commit comments

Comments
 (0)