Spring Test Error java.lang.ClassNotFoundException: org.junit.platform.engine.reporting.OutputDirectoryProvider

พอดีช่วงนี้ลองปัดฝุ่น Java ป่าวหรอกจริงๆไปลอง Course manning live project อันเก่าที่ดองไว้ ซื้อมาตอน 10 usd แล้วมาลองดู Spring Version ใหม่ ของเดิมนน่าจะปี 2022-2023 แต่พอขยับ แล้วเจอ Error

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.5.3:test (default-test) on project bestInsuranceApi:
[ERROR]
[ERROR] See D:\2WarRoom\2025ManningSpring\02ConnectDB\pingkunga-connect-to-a-database-lp\target\surefire-reports for the individual test results.
[ERROR] See dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] org/junit/platform/engine/reporting/OutputDirectoryProvider
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] org/junit/platform/engine/reporting/OutputDirectoryProvider
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:628)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:285)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:250)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1337)

ตอนแรกผมคิดมาครึ่งวันเลย แล้วพอมาเจอ Issue นี้ ถึงบางอ้อเลยครับ มัน Bug

สรุป ผมเลยย้อนกลับไปใช้ Version ล่าสุดเมื่อปลายปี 2025 กับเดือนแรกของปี 2025 แทนครับ อันนี้เป็น pom ที่แก้ เผื่อใครเจอปัญหาครับ ^__^

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>3.4.5</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.bestinsurance</groupId>
	<artifactId>bestInsuranceApi</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>
	<name>bestInsuranceApi</name>
	<description>BestInsurance Api</description>
	<url/>
	<licenses>
		<license/>
	</licenses>
	<developers>
		<developer/>
	</developers>
	<scm>
		<connection/>
		<developerConnection/>
		<tag/>
		<url/>
	</scm>
	<properties>
		<java.version>21</java.version>
	</properties>
<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<version>3.3.6</version>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>org.springdoc</groupId>
			<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
			<version>2.8.6</version>
		</dependency>

		<!-- org.springframework.boot:spring-boot-starter-data-jpa 
		   / org.springframework.boot:spring-boot-starter-validation 
		   / org.liquibase:liquibase-core 
		   / org.postgresql:postgresql-->

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-validation</artifactId>
		</dependency>
		<dependency>
			<groupId>org.liquibase</groupId>
			<artifactId>liquibase-core</artifactId>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
		<dependency>
			<groupId>org.postgresql</groupId>
			<artifactId>postgresql</artifactId>
			<version>42.7.5</version>
			<scope>runtime</scope>
		</dependency>

		<!-- Test Container -->
		<!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher -->
		<dependency>
			<groupId>org.junit.platform</groupId>
			<artifactId>junit-platform-launcher</artifactId>
			<version>1.11.3</version>
			<scope>test</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.testcontainers/testcontainers -->
		<dependency>
			<groupId>org.testcontainers</groupId>
			<artifactId>testcontainers</artifactId>
			<version>1.20.6</version>
			<scope>test</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.testcontainers/junit-jupiter -->
		<dependency>
			<groupId>org.testcontainers</groupId>
			<artifactId>junit-jupiter</artifactId>
			<version>1.20.6</version>
			<scope>test</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.testcontainers/postgresql -->
		<dependency>
			<groupId>org.testcontainers</groupId>
			<artifactId>postgresql</artifactId>
			<version>1.20.6</version>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<image>
						<name>best_insurance/api</name>
					</image>
				</configuration>
			</plugin>
		</plugins>
	</build>

</project>

สำหรับการเรียนนอกจาก Flyway แล้ว ยังมีตัว liquibase ที่ทำคล้ายๆ รวมถึง Idea การทำ API ด้วย จบหยุดยาวครับ Happy Long Weekend

Reference


Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts sent to your email.