Skip to content

spring-boot.run.useTestClasspath does not take target/test-classes in account #36115

Open
@fjakop

Description

@fjakop

spring-boot-maven-plugin v3.1.0
OpenJDK 20

When I put an @SpringBootApplication annotated class into the test folder src/test/java and activate useTestClasspath the class cannot be loaded in start goal.

[INFO] --- spring-boot-maven-plugin:3.1.0:start (start-apidoc-application) @ mymodule ---
[INFO] Attaching agents: []
Fehler: Hauptklasse de.my.OpenApiApplication konnte nicht gefunden oder geladen werden
Ursache: java.lang.ClassNotFoundException: de.my.OpenApiApplication

I have verified that the compiled class is present at target/test-classes/de.my. Putting the package and the class to src/main/java works.

pom.xml

<build>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
			<version>3.1.0</version>
			<configuration>
				<useTestClasspath>true</useTestClasspath>
				<mainClass>de.my.OpenApiApplication</mainClass>
			</configuration>
			<executions>
				<execution>
					<id>start-apidoc-application</id>
					<phase>prepare-package</phase>
					<goals>
						<goal>start</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>

The docs state in https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/#goals-start-parameters-details-useTestClasspath

Flag to include the test classpath when running.

I would expect target/test-classes to be part of the test classpath so the classesthere should be taken into account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions