Maven Failsafe Classpath

I figured it out, so I'm answering my own quesiton in case someone else has the same problem.

It turns out that maven-failsafe-plugin does not add target/classes directory to the classpath, but rather the resulting jar, which works fine in most cases.

When it comes to Spring Boot, however, the resulting jar contains Spring Boot custom classloader classes in place of contents of target/classes directory, which are moved to directory BOOT-INF/classes. Since maven-failsafe-plugin uses 'regular' classloader it only loads Spring Boot classloader classes, failing in the first place it is expected to use one of the project classes.

To run IT tests in Spring Boot project, one has to exclude the packaged jar from dependencies and add either the original, unmodified jar or target/classes directory, which is what I did.

The correct configuration for maven-failsafe-plugin and Spring Boot is:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.21.0</version>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                 <goal>verify</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <classpathDependencyExcludes>
            <classpathDependencyExcludes>${groupId}:${artifactId}</classpathDependencyExcludes>
        </classpathDependencyExcludes>
        <additionalClasspathElements>
            <additionalClasspathElement>${project.build.outputDirectory}</additionalClasspathElement>
        </additionalClasspathElements>
    </configuration>
</plugin>

Another option that seems to work is to add a classifier to the spring-boot-maven-plugin configuration. This causes SpringBoot to leave the "default" build target jar alone and instead create the SpringBoot uber jar with the classifier name appended.

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
          <classifier>sb-executable</classifier>
    </configuration>
</plugin>