diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..48ada1a
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,23 @@
+name: Build
+on: [push, pull_request]
+jobs:
+ maven:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-java@v4
+ with:
+ distribution: temurin
+ java-version: '17'
+ cache: maven
+ - run: mvn -B -V clean package
+ gradle:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-java@v4
+ with:
+ distribution: temurin
+ java-version: '17'
+ - uses: gradle/actions/setup-gradle@v3
+ - run: ./gradlew -V clean bootJar
diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties
index c954cec..3c11064 100644
--- a/.mvn/wrapper/maven-wrapper.properties
+++ b/.mvn/wrapper/maven-wrapper.properties
@@ -1 +1 @@
-distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
+distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
diff --git a/build.gradle b/build.gradle
index 09f1083..7bf5992 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,7 +3,8 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE")
+ classpath("org.springframework.boot:spring-boot-gradle-plugin:2.7.18")
+ classpath("io.spring.gradle:dependency-management-plugin:1.0.15.RELEASE")
}
}
@@ -14,19 +15,28 @@ apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
bootJar {
- baseName = 'gs-spring-boot'
- version = '0.1.0'
+ archiveBaseName = 'gs-spring-boot'
+ archiveVersion = '0.1.0'
}
repositories {
mavenCentral()
}
-sourceCompatibility = 1.8
-targetCompatibility = 1.8
+java {
+ toolchain {
+ languageVersion = JavaLanguageVersion.of(17)
+ }
+}
-dependencies {
- compile("org.springframework.boot:spring-boot-starter-web")
- testCompile("junit:junit")
+tasks.withType(JavaCompile) {
+ options.release = 17
}
+dependencies {
+ implementation("org.springframework.boot:spring-boot-starter-web")
+ implementation("org.springframework.boot:spring-boot-starter-jdbc")
+ implementation("javax.annotation:javax.annotation-api:1.3.2")
+ runtimeOnly("com.h2database:h2")
+ testImplementation("junit:junit")
+}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index a2ff3cc..03a8d13 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-bin.zip
diff --git a/gradlew b/gradlew
old mode 100644
new mode 100755
diff --git a/mvnw b/mvnw
old mode 100644
new mode 100755
diff --git a/pom.xml b/pom.xml
index 63f5cbd..c805905 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,21 +5,16 @@
org.springframework
gs-spring-boot
- pom
+ jar
0.1.0
org.springframework.boot
spring-boot-starter-parent
- 2.0.2.RELEASE
+ 2.7.18
-
- org.springframework.boot
- spring-boot-properties-migrator
- runtime
-
org.springframework.boot
spring-boot-starter-web
@@ -32,15 +27,31 @@
com.h2database
h2
+
+ javax.annotation
+ javax.annotation-api
+ 1.3.2
+
- 1.8
+ 17
+ 17
+ 3.13.0
+ 3.5.6
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+ ${maven.compiler.release}
+
+
org.springframework.boot
spring-boot-maven-plugin
diff --git a/src/main/java/hello/Application.java b/src/main/java/hello/Application.java
index 7cf8faf..0c7fb6b 100644
--- a/src/main/java/hello/Application.java
+++ b/src/main/java/hello/Application.java
@@ -17,11 +17,13 @@
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.client.RestTemplate;
+import org.springframework.web.client.RestClientException;
@SpringBootApplication
public class Application implements CommandLineRunner {
private static final Logger log = LoggerFactory.getLogger(Application.class);
+ private static final String QUOTERS_URL = "http://gturnquist-quoters.cfapps.io/api/random";
public static void main(String[] args) {
@@ -36,8 +38,7 @@ public static void main(String[] args) {
}
RestTemplate restTemplate = new RestTemplate();
- Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
- log.info(quote.toString());
+ logRandomQuote(restTemplate);
}
@@ -49,12 +50,23 @@ public RestTemplate restTemplate(RestTemplateBuilder builder) {
@Bean
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
return args -> {
- Quote quote = restTemplate.getForObject(
- "http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
- log.info(quote.toString());
+ logRandomQuote(restTemplate);
};
}
+ private static void logRandomQuote(RestTemplate restTemplate) {
+ try {
+ Quote quote = restTemplate.getForObject(QUOTERS_URL, Quote.class);
+ if (quote == null) {
+ log.warn("Unable to retrieve random quote from {}", QUOTERS_URL);
+ } else {
+ log.info(quote.toString());
+ }
+ } catch (RestClientException ex) {
+ log.warn("Unable to retrieve random quote from {}", QUOTERS_URL, ex);
+ }
+ }
+
@Autowired
JdbcTemplate jdbcTemplate;