From 3cabc7b8ffa384e39bb51d2c3cb973cef8761b82 Mon Sep 17 00:00:00 2001 From: Harkamal Randhawa Date: Fri, 13 Mar 2026 10:25:50 -0600 Subject: [PATCH] Add startup checks --- pom.xml | 21 ++++++++++++++++ .../petshop/backend/BackendApplication.java | 1 + .../petshop/backend/DevStackApplication.java | 1 + .../backend/RuntimeClasspathValidator.java | 24 +++++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 src/main/java/com/petshop/backend/RuntimeClasspathValidator.java diff --git a/pom.xml b/pom.xml index 1d3a79ac..de496351 100644 --- a/pom.xml +++ b/pom.xml @@ -107,6 +107,27 @@ 25 + + org.apache.maven.plugins + maven-enforcer-plugin + 3.5.0 + + + require-java-25 + + enforce + + + + + [25,) + JDK 25 or newer is required. Configure IntelliJ and Maven to use JDK 25 before running the backend. + + + + + + org.springframework.boot spring-boot-maven-plugin diff --git a/src/main/java/com/petshop/backend/BackendApplication.java b/src/main/java/com/petshop/backend/BackendApplication.java index 2a9718c3..87268e9a 100644 --- a/src/main/java/com/petshop/backend/BackendApplication.java +++ b/src/main/java/com/petshop/backend/BackendApplication.java @@ -9,6 +9,7 @@ import org.springframework.data.web.config.EnableSpringDataWebSupport; @EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO) public class BackendApplication { public static void main(String[] args) { + RuntimeClasspathValidator.validate(); new SpringApplicationBuilder(BackendApplication.class) .initializers(new FlywayContextInitializer()) .run(args); diff --git a/src/main/java/com/petshop/backend/DevStackApplication.java b/src/main/java/com/petshop/backend/DevStackApplication.java index f60e9957..4fd47ffc 100644 --- a/src/main/java/com/petshop/backend/DevStackApplication.java +++ b/src/main/java/com/petshop/backend/DevStackApplication.java @@ -28,6 +28,7 @@ public class DevStackApplication { try { validateJavaVersion(); + RuntimeClasspathValidator.validate(); docker.ensureDockerAvailable(); docker.startDatabase(); context = new SpringApplicationBuilder(BackendApplication.class) diff --git a/src/main/java/com/petshop/backend/RuntimeClasspathValidator.java b/src/main/java/com/petshop/backend/RuntimeClasspathValidator.java new file mode 100644 index 00000000..ad18d198 --- /dev/null +++ b/src/main/java/com/petshop/backend/RuntimeClasspathValidator.java @@ -0,0 +1,24 @@ +package com.petshop.backend; + +import java.net.URL; + +final class RuntimeClasspathValidator { + + private RuntimeClasspathValidator() { + } + + static void validate() { + if (!resourceExists("application.yml")) { + throw new IllegalStateException("Backend resources are missing from the runtime classpath. Reimport the Maven project in IntelliJ and run the shared Maven run configuration."); + } + if (!resourceExists("db/migration/V1__baseline_schema.sql")) { + throw new IllegalStateException("Flyway migration files are missing from the runtime classpath. Reimport the Maven project in IntelliJ and run the shared Maven run configuration."); + } + } + + private static boolean resourceExists(String path) { + ClassLoader classLoader = RuntimeClasspathValidator.class.getClassLoader(); + URL resource = classLoader.getResource(path); + return resource != null; + } +}