Spring-boot-maven-plugin run mainCLass in test package

39 Views Asked by At

I need to run a SpringBootApplication which is in test package during my integration test with spring-boot-maven-plugin (start and stop goals)

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
    <mainClass>launchers.ApplicationTestMode</mainClass>
    </configuration>
</plugin>

but I get with no surprise a ClassNotFoundException

How to run this SpringBootApplication in test package ?

1

There are 1 best solutions below

0
the-bug On

I was able to get this running with:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <directories>
            <directory>target/test-classes</directory>
            <directory>target/classes</directory>
        </directories>
        <mainClass>launchers.ApplicationTestMode</mainClass>
    </configuration>
</plugin>

You have to add the test-classes. I assume you are using the SpringBootApplication from your main code. So add the original classes as well. If you use some test dependencies(e.g. testcontainers) in you launchers.ApplicationTestMode, then add <useTestClasspath>true</useTestClasspath>