Skip to content

Commit b58d0be

Browse files
Build with Java 21 (#370)
- Use Java 21 to build sample application - Use Openrewrite with recipe org.openrewrite.java.migrate.UpgradeToJava21 to demonstrate newer JDK APIs - Update some outdated build plugins - Bump enforced min. Maven to 3.6.3 -> required by cds-maven-plugin --------- Co-authored-by: Marc Becker <[email protected]>
1 parent eed4c2f commit b58d0be

File tree

11 files changed

+25
-24
lines changed

11 files changed

+25
-24
lines changed

.github/workflows/maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Set up JDK
2525
uses: actions/setup-java@v4
2626
with:
27-
java-version: 17
27+
java-version: 21
2828
distribution: 'sapmachine'
2929
- name: Build with Maven
3030
run: mvn -ntp -B clean install

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ The following sections describe how to set up, build, and run the project.
105105

106106
## Prerequisites
107107

108-
Make sure you have set up a development environment (that means, you’ve installed the CDS Compiler, Java, and Apache Maven) [as described here](https://cap.cloud.sap/docs/java/getting-started).
108+
Make sure you have set up a development environment (that means, you’ve installed the CDS Compiler, Java 21, and Apache Maven) [as described here](https://cap.cloud.sap/docs/java/getting-started).
109+
This sample application requires a Java 21 compatible JDK. We recommend using [SapMachine 21](https://sap.github.io/SapMachine/).
109110

110111
## Clone Build & Run
111112

integration-tests/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<plugin>
5050
<groupId>org.apache.maven.plugins</groupId>
5151
<artifactId>maven-surefire-plugin</artifactId>
52-
<version>3.2.5</version>
52+
<version>3.5.0</version>
5353
<configuration>
5454
<failIfNoTests>false</failIfNoTests>
5555
</configuration>
@@ -67,7 +67,7 @@
6767
<!-- Tests ending with *IT.java will be executed here -->
6868
<groupId>org.apache.maven.plugins</groupId>
6969
<artifactId>maven-failsafe-plugin</artifactId>
70-
<version>3.2.5</version>
70+
<version>3.5.0</version>
7171
<executions>
7272
<execution>
7373
<goals>
@@ -108,7 +108,7 @@
108108
<plugin>
109109
<groupId>org.codehaus.mojo</groupId>
110110
<artifactId>exec-maven-plugin</artifactId>
111-
<version>3.3.0</version>
111+
<version>3.4.1</version>
112112
<executions>
113113
<execution>
114114
<phase>pre-integration-test</phase>

pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
<revision>1.0.0-SNAPSHOT</revision>
2323

2424
<!-- DEPENDENCIES VERSION -->
25-
<jdk.version>17</jdk.version>
25+
<jdk.version>21</jdk.version>
2626
<cds.services.version>3.2.0</cds.services.version>
2727
<cloud.sdk.version>5.11.0</cloud.sdk.version>
2828
<xsuaa.version>3.5.3</xsuaa.version>
2929
<cf-java-logging-support.version>3.8.4</cf-java-logging-support.version>
30-
<cds.cdsdk-version>8.2.0</cds.cdsdk-version>
30+
<cds.cdsdk-version>8.2.1</cds.cdsdk-version>
3131
</properties>
3232

3333
<modules>
@@ -80,7 +80,7 @@
8080
<plugin>
8181
<groupId>org.apache.maven.plugins</groupId>
8282
<artifactId>maven-compiler-plugin</artifactId>
83-
<version>3.12.1</version>
83+
<version>3.13.0</version>
8484
<configuration>
8585
<release>${jdk.version}</release>
8686
<encoding>UTF-8</encoding>
@@ -100,7 +100,7 @@
100100
<plugin>
101101
<groupId>org.apache.maven.plugins</groupId>
102102
<artifactId>maven-surefire-plugin</artifactId>
103-
<version>3.2.5</version>
103+
<version>3.5.0</version>
104104
<configuration>
105105
<failIfNoTests>true</failIfNoTests>
106106
</configuration>
@@ -109,7 +109,7 @@
109109
<plugin>
110110
<groupId>org.apache.maven.plugins</groupId>
111111
<artifactId>maven-failsafe-plugin</artifactId>
112-
<version>3.2.5</version>
112+
<version>3.5.0</version>
113113
</plugin>
114114

115115
<!-- POM FLATTENING FOR CI FRIENDLY VERSIONS -->
@@ -143,7 +143,7 @@
143143
<plugin>
144144
<groupId>org.apache.maven.plugins</groupId>
145145
<artifactId>maven-enforcer-plugin</artifactId>
146-
<version>3.4.1</version>
146+
<version>3.5.0</version>
147147
<executions>
148148
<execution>
149149
<id>Project Structure Checks</id>
@@ -153,7 +153,7 @@
153153
<configuration>
154154
<rules>
155155
<requireMavenVersion>
156-
<version>3.5</version>
156+
<version>3.6.3</version>
157157
</requireMavenVersion>
158158
<requireJavaVersion>
159159
<version>${jdk.version}</version>

srv/src/main/java/my/bookshop/handlers/AdminServiceAddressHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void updateBusinessPartnerAddresses(BusinessPartnerChangedContext context
140140
.filter(ext -> ext.getId().equals(rep.getId()))
141141
.findFirst();
142142

143-
if(!matching.isPresent()) {
143+
if(matching.isEmpty()) {
144144
rep.setTombstone(true);
145145
} else {
146146
matching.get().forEach(rep::put);

srv/src/main/java/my/bookshop/handlers/CatalogServiceHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public void onSubmitOrder(SubmitOrderContext context) {
181181

182182
private void discountBooksWithMoreThan111Stock(Books b, boolean premium) {
183183
if (b.getStock() != null && b.getStock() > 111) {
184-
b.setTitle(String.format("%s -- %s%% discount", b.getTitle(), premium ? 14 : 11));
184+
b.setTitle("%s -- %s%% discount".formatted(b.getTitle(), premium ? 14 : 11));
185185
}
186186
}
187187

srv/src/main/java/my/bookshop/handlers/NotesServiceHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class NotesServiceHandler implements EventHandler {
5656
Result readAddresses(CdsReadEventContext context) {
5757
List<? extends Segment> segments = context.getCqn().ref().segments();
5858
// via note
59-
if(segments.size() == 2 && segments.get(0).id().equals(Notes_.CDS_NAME)) {
59+
if(segments.size() == 2 && segments.getFirst().id().equals(Notes_.CDS_NAME)) {
6060
Map<String, Object> noteKeys = analyzer.analyze(context.getCqn()).rootKeys();
6161
Notes note = context.getService().run(Select.from(NOTES).columns(n -> n.address_businessPartner(), n -> n.address_ID()).matching(noteKeys)).single(Notes.class);
6262
CqnSelect addressOfNote = CQL.copy(context.getCqn(), new Modifier() {
@@ -115,7 +115,7 @@ public List<CqnSelectListItem> items(List<CqnSelectListItem> items) {
115115
void readNotes(CdsReadEventContext context) {
116116
List<? extends Segment> segments = context.getCqn().ref().segments();
117117
// via addresses
118-
if(segments.size() == 2 && segments.get(0).id().equals(Addresses_.CDS_NAME)) {
118+
if(segments.size() == 2 && segments.getFirst().id().equals(Addresses_.CDS_NAME)) {
119119
Map<String, Object> addressKeys = analyzer.analyze(context.getCqn()).rootKeys();
120120
CqnSelect notesOfAddress = CQL.copy(context.getCqn(), new Modifier() {
121121

srv/src/main/java/my/bookshop/handlers/SubscriptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class SubscriptionHandler implements EventHandler {
2424

2525
@After
2626
public void afterSubscribe(SubscribeEventContext context) {
27-
String msg = String.format("New tenant '%s' subscribed.", context.getTenant());
27+
String msg = "New tenant '%s' subscribed.".formatted(context.getTenant());
2828

2929
// send audit log security message to provider tenant as user's tenant is null
3030
auditLog.logSecurityEvent("tenant subscribed", msg);

srv/src/test/java/my/bookshop/AdminServiceAddressITestBase.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ public void testOrderWithAddress() throws InterruptedException {
5050
order.setShippingAddressId("100");
5151

5252
String id = UUID.randomUUID().toString();
53-
client.put().uri(String.format(orderURI, id))
53+
client.put().uri(orderURI.formatted(id))
5454
.headers(this::adminCredentials)
5555
.header("Content-Type", "application/json")
5656
.bodyValue(order.toJson())
5757
.exchange()
5858
.expectStatus().isCreated();
5959

60-
client.get().uri(String.format(orderURI, id) + "?$expand=shippingAddress").headers(this::adminCredentials).exchange()
60+
client.get().uri(orderURI.formatted(id) + "?$expand=shippingAddress").headers(this::adminCredentials).exchange()
6161
.expectStatus().isOk()
6262
.expectBody()
6363
.jsonPath("$.ID").isEqualTo(id)
@@ -66,7 +66,7 @@ public void testOrderWithAddress() throws InterruptedException {
6666
.jsonPath("$.shippingAddress.businessPartner").isEqualTo("10401010")
6767
.jsonPath("$.shippingAddress.houseNumber").isEqualTo("16");
6868

69-
client.get().uri(String.format(orderURI, id) + "/shippingAddress").headers(this::adminCredentials).exchange()
69+
client.get().uri(orderURI.formatted(id) + "/shippingAddress").headers(this::adminCredentials).exchange()
7070
.expectStatus().isOk()
7171
.expectBody()
7272
.jsonPath("$.ID").isEqualTo("100")
@@ -88,15 +88,15 @@ public void afterClose(boolean completed) {
8888
ABusinessPartnerAddress address = ABusinessPartnerAddress.create();
8989
address.setHouseNumber("17");
9090

91-
client.patch().uri(String.format(remoteAddressURI, "10401010", "100")).headers(this::authenticatedCredentials)
91+
client.patch().uri(remoteAddressURI.formatted("10401010", "100")).headers(this::authenticatedCredentials)
9292
.header("Content-Type", "application/json")
9393
.bodyValue(address.toJson())
9494
.exchange()
9595
.expectStatus().isOk();
9696

9797
// wait for remote address update
9898
latch.await(30, TimeUnit.SECONDS);
99-
client.get().uri(String.format(orderURI, id) + "/shippingAddress").headers(this::adminCredentials).exchange()
99+
client.get().uri(orderURI.formatted(id) + "/shippingAddress").headers(this::adminCredentials).exchange()
100100
.expectStatus().isOk()
101101
.expectBody()
102102
.jsonPath("$.ID").isEqualTo("100")

srv/src/test/java/my/bookshop/CatalogServiceITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
public class CatalogServiceITest {
2828

2929
private static final String booksURI = "/api/browse/Books";
30-
private static final String addReviewURI = String.format("%s(ID=%s)/CatalogService.addReview", booksURI, "f846b0b9-01d4-4f6d-82a4-d79204f62278");
30+
private static final String addReviewURI = "%s(ID=%s)/CatalogService.addReview".formatted(booksURI, "f846b0b9-01d4-4f6d-82a4-d79204f62278");
3131

3232
private static final String USER_USER_STRING = "user";
3333
private static final String ADMIN_USER_STRING = "admin";

0 commit comments

Comments
 (0)