Skip to content

Commit f0934ae

Browse files
Upgrade to Java 17 LTS and Spring Boot 2.7.18
Co-Authored-By: Toby Drinkall <toby.drinkall@cognition.ai>
1 parent c31d0c6 commit f0934ae

8 files changed

Lines changed: 75 additions & 23 deletions

File tree

.github/workflows/build.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Build
2+
on: [push, pull_request]
3+
jobs:
4+
maven:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
- uses: actions/setup-java@v4
9+
with:
10+
distribution: temurin
11+
java-version: '17'
12+
cache: maven
13+
- run: mvn -B -V clean package
14+
gradle:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-java@v4
19+
with:
20+
distribution: temurin
21+
java-version: '17'
22+
- uses: gradle/actions/setup-gradle@v3
23+
- run: ./gradlew -V clean bootJar
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip

build.gradle

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ buildscript {
33
mavenCentral()
44
}
55
dependencies {
6-
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE")
6+
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.7.18")
7+
classpath("io.spring.gradle:dependency-management-plugin:1.0.15.RELEASE")
78
}
89
}
910

@@ -14,19 +15,28 @@ apply plugin: 'org.springframework.boot'
1415
apply plugin: 'io.spring.dependency-management'
1516

1617
bootJar {
17-
baseName = 'gs-spring-boot'
18-
version = '0.1.0'
18+
archiveBaseName = 'gs-spring-boot'
19+
version = '0.1.0'
1920
}
2021

2122
repositories {
2223
mavenCentral()
2324
}
2425

25-
sourceCompatibility = 1.8
26-
targetCompatibility = 1.8
26+
java {
27+
toolchain {
28+
languageVersion = JavaLanguageVersion.of(17)
29+
}
30+
}
2731

28-
dependencies {
29-
compile("org.springframework.boot:spring-boot-starter-web")
30-
testCompile("junit:junit")
32+
tasks.withType(JavaCompile) {
33+
options.release = 17
3134
}
3235

36+
dependencies {
37+
implementation("org.springframework.boot:spring-boot-starter-web")
38+
implementation("org.springframework.boot:spring-boot-starter-jdbc")
39+
implementation("javax.annotation:javax.annotation-api:1.3.2")
40+
runtimeOnly("com.h2database:h2")
41+
testImplementation("junit:junit")
42+
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-bin.zip

gradlew

100644100755
File mode changed.

mvnw

100644100755
File mode changed.

pom.xml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,16 @@
55

66
<groupId>org.springframework</groupId>
77
<artifactId>gs-spring-boot</artifactId>
8-
<packaging>pom</packaging>
8+
<packaging>jar</packaging>
99
<version>0.1.0</version>
1010

1111
<parent>
1212
<groupId>org.springframework.boot</groupId>
1313
<artifactId>spring-boot-starter-parent</artifactId>
14-
<version>2.0.2.RELEASE</version>
14+
<version>2.7.18</version>
1515
</parent>
1616

1717
<dependencies>
18-
<dependency>
19-
<groupId>org.springframework.boot</groupId>
20-
<artifactId>spring-boot-properties-migrator</artifactId>
21-
<scope>runtime</scope>
22-
</dependency>
2318
<dependency>
2419
<groupId>org.springframework.boot</groupId>
2520
<artifactId>spring-boot-starter-web</artifactId>
@@ -32,15 +27,31 @@
3227
<groupId>com.h2database</groupId>
3328
<artifactId>h2</artifactId>
3429
</dependency>
30+
<dependency>
31+
<groupId>javax.annotation</groupId>
32+
<artifactId>javax.annotation-api</artifactId>
33+
<version>1.3.2</version>
34+
</dependency>
3535
</dependencies>
3636

3737
<properties>
38-
<java.version>1.8</java.version>
38+
<java.version>17</java.version>
39+
<maven.compiler.release>17</maven.compiler.release>
40+
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
41+
<maven-surefire-plugin.version>3.5.6</maven-surefire-plugin.version>
3942
</properties>
4043

4144

4245
<build>
4346
<plugins>
47+
<plugin>
48+
<groupId>org.apache.maven.plugins</groupId>
49+
<artifactId>maven-compiler-plugin</artifactId>
50+
<version>${maven-compiler-plugin.version}</version>
51+
<configuration>
52+
<release>${maven.compiler.release}</release>
53+
</configuration>
54+
</plugin>
4455
<plugin>
4556
<groupId>org.springframework.boot</groupId>
4657
<artifactId>spring-boot-maven-plugin</artifactId>

src/main/java/hello/Application.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
import org.springframework.context.annotation.Bean;
1818
import org.springframework.jdbc.core.JdbcTemplate;
1919
import org.springframework.web.client.RestTemplate;
20+
import org.springframework.web.client.RestClientException;
2021

2122
@SpringBootApplication
2223
public class Application implements CommandLineRunner {
2324

2425
private static final Logger log = LoggerFactory.getLogger(Application.class);
26+
private static final String QUOTERS_URL = "http://gturnquist-quoters.cfapps.io/api/random";
2527

2628
public static void main(String[] args) {
2729

@@ -36,8 +38,7 @@ public static void main(String[] args) {
3638
}
3739

3840
RestTemplate restTemplate = new RestTemplate();
39-
Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
40-
log.info(quote.toString());
41+
logRandomQuote(restTemplate);
4142
}
4243

4344

@@ -49,12 +50,19 @@ public RestTemplate restTemplate(RestTemplateBuilder builder) {
4950
@Bean
5051
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
5152
return args -> {
52-
Quote quote = restTemplate.getForObject(
53-
"http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
54-
log.info(quote.toString());
53+
logRandomQuote(restTemplate);
5554
};
5655
}
5756

57+
private static void logRandomQuote(RestTemplate restTemplate) {
58+
try {
59+
Quote quote = restTemplate.getForObject(QUOTERS_URL, Quote.class);
60+
log.info(quote.toString());
61+
} catch (RestClientException ex) {
62+
log.warn("Unable to retrieve random quote from {}", QUOTERS_URL, ex);
63+
}
64+
}
65+
5866

5967
@Autowired
6068
JdbcTemplate jdbcTemplate;

0 commit comments

Comments
 (0)