-
Notifications
You must be signed in to change notification settings - Fork 1
Upgrade to Java 17 and Spring Boot 2.7.18 (Maven + Gradle) #58
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
base: master
Are you sure you want to change the base?
Changes from all commits
a0bb290
20c978f
2f4e18f
8255bf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| /.idea/ | ||
| /.idea/ | ||
| target/ | ||
| build/ | ||
| .gradle/ |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,29 @@ 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) | ||
| } | ||
| } | ||
|
|
||
| tasks.withType(JavaCompile) { | ||
| options.release = 17 | ||
| } | ||
|
|
||
| dependencies { | ||
| compile("org.springframework.boot:spring-boot-starter-web") | ||
| testCompile("junit:junit") | ||
| implementation("org.springframework.boot:spring-boot-starter-web") | ||
| implementation("org.springframework.boot:spring-boot-starter-jdbc") | ||
| runtimeOnly("com.h2database:h2") | ||
| runtimeOnly("org.springframework.boot:spring-boot-properties-migrator") | ||
| testImplementation("junit:junit") | ||
|
Comment on lines
+37
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Info: properties-migrator kept on the runtime classpath in both builds
Was this helpful? React with 👍 or 👎 to provide feedback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aligned in 20c978f: added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scopes now match exactly: On the migrator: agreed it's temporary, and I'd remove it in a follow-up rather than here. This repo has no tests and no CI, so a startup report of renamed/removed properties is the only regression signal available while the Boot 2.0 -> 2.7 jump is being reviewed; dropping it in the same PR would remove that signal before anyone has exercised the upgrade. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Position unchanged from my earlier reply in this thread: the migrator stays for this PR and comes out in a follow-up. "Reports no renamed properties" is only true for the paths I exercised by hand — with no tests and no CI, a reviewer running this branch is the next chance to catch a rename, and removing the migrator now removes that chance. |
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,13 +5,13 @@ | |
|
|
||
| <groupId>org.springframework</groupId> | ||
| <artifactId>gs-spring-boot</artifactId> | ||
| <packaging>pom</packaging> | ||
| <packaging>jar</packaging> | ||
| <version>0.1.0</version> | ||
|
|
||
| <parent> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-parent</artifactId> | ||
| <version>2.0.2.RELEASE</version> | ||
| <version>2.7.18</version> | ||
| </parent> | ||
|
|
||
| <dependencies> | ||
|
|
@@ -31,11 +31,15 @@ | |
| <dependency> | ||
| <groupId>com.h2database</groupId> | ||
| <artifactId>h2</artifactId> | ||
| <scope>runtime</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <properties> | ||
| <java.version>1.8</java.version> | ||
| <java.version>17</java.version> | ||
| <maven.compiler.release>17</maven.compiler.release> | ||
| <maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version> | ||
| <maven-surefire-plugin.version>3.5.6</maven-surefire-plugin.version> | ||
|
Comment on lines
+41
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Info: Overridden plugin versions rely on parent property names
Was this helpful? React with 👍 or 👎 to provide feedback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed effective, not inert. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping both. |
||
| </properties> | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| rootProject.name = 'gs-spring-boot' |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Info: Legacy H2 DDL kept intentionally, but H2 2.x compatibility is version-fragile
(Refers to lines 72-73) Was this helpful? React with 👍 or 👎 to provide feedback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left as-is deliberately. The point of the H2 note in the description is that the legacy grammar still parses on the version Boot 2.7.18 manages (2.1.214) — verified at runtime here. Modernising the DDL is a good follow-up but is a source change unrelated to the Java/Boot upgrade, so I'd rather it not ride along in this PR. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,13 +16,16 @@ | |
| import org.springframework.context.ApplicationContext; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
| import org.springframework.web.client.RestClientException; | ||
| import org.springframework.web.client.RestTemplate; | ||
|
|
||
| @SpringBootApplication | ||
| public class Application implements CommandLineRunner { | ||
|
|
||
| private static final Logger log = LoggerFactory.getLogger(Application.class); | ||
|
|
||
| private static final String QUOTE_URL = "http://gturnquist-quoters.cfapps.io/api/random"; | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| ApplicationContext ctx = SpringApplication.run(Application.class, args); | ||
|
|
@@ -35,9 +38,16 @@ public static void main(String[] args) { | |
| System.out.println(beanName); | ||
| } | ||
|
|
||
| RestTemplate restTemplate = new RestTemplate(); | ||
| Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class); | ||
| log.info(quote.toString()); | ||
| logRandomQuote(new RestTemplate()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Info: Quote is still fetched twice per startup The quote is fetched once from the Was this helpful? React with 👍 or 👎 to provide feedback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pre-existing duplication, left as-is: both call sites are demo code from the original Spring guide, and consolidating them changes runtime behaviour (one fewer startup fetch) beyond the scope of a version upgrade. Worth noting the second WARN is now visible only because the host is dead; when the endpoint worked, both paths logged a quote. Happy to collapse |
||
| } | ||
|
|
||
| private static void logRandomQuote(RestTemplate restTemplate) { | ||
| try { | ||
| Quote quote = restTemplate.getForObject(QUOTE_URL, Quote.class); | ||
| log.info(String.valueOf(quote)); | ||
| } catch (RestClientException e) { | ||
| log.warn("Could not fetch a quote from {}: {}", QUOTE_URL, e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -48,11 +58,7 @@ 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()); | ||
| }; | ||
| return args -> logRandomQuote(restTemplate); | ||
|
Comment on lines
59
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Info: Two CommandLineRunner beans still run in an unspecified order
Was this helpful? React with 👍 or 👎 to provide feedback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pre-existing, unchanged, and left alone. The |
||
| } | ||
|
|
||
|
|
||
|
|
@@ -80,8 +86,9 @@ public void run(String... args) throws Exception { | |
|
|
||
| log.info("Querying for customer records where first_name = 'Josh':"); | ||
| jdbcTemplate.query( | ||
| "SELECT id, first_name, last_name FROM customers WHERE first_name = ?", new Object[]{"Josh"}, | ||
| (rs, rowNum) -> new Customer(rs.getLong("id"), rs.getString("first_name"), rs.getString("last_name")) | ||
| "SELECT id, first_name, last_name FROM customers WHERE first_name = ?", | ||
| (rs, rowNum) -> new Customer(rs.getLong("id"), rs.getString("first_name"), rs.getString("last_name")), | ||
| "Josh" | ||
| ).forEach(customer -> log.info(customer.toString())); | ||
|
|
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| #server.port=8081 |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Info: Gradle toolchain requires a locally installed JDK 17
The
java.toolchainblock plusoptions.release = 17means Gradle will fail with a toolchain-resolution error on machines without a JDK 17 installed, since no toolchain resolver plugin is configured. This is documented in the README, but it makes the Gradle build stricter than the Maven build, which compiles with whatever JDK runs Maven as long as it supports--release 17.Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documented in 8255bf2: the README's Prerequisites now say JDK 17 (it said "Java sdk"), Getting Started calls out that the Gradle toolchain will not download a JDK because no resolver is configured, and both the Maven and Gradle build/run command pairs are listed. Kept the toolchain block rather than adding foojay-resolver — failing loudly with "No matching toolchains found" is better than silently compiling against whatever JDK happens to be on PATH, and
options.release = 17alone would not pin the JVM that runs the build.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, and intended: I'd rather the Gradle build refuse to run on a wrong JDK than compile with whatever is on PATH. Note Maven isn't as loose as it looks either —
--release 17fails outright on a JDK older than 17, so the practical difference is only that Maven tolerates a newer JDK while Gradle pins exactly 17.