Document how to configure Maven's Failsafe plugin when not using spring-boot-starter-parent
See original GitHub issueWhile migrating an existing application from 2.3.7.RELEASE
to 2.4.3
I faced an issue running integration tests complaining with:
java.lang.IllegalStateException: Failed to find merged annotation for @org.springframework.test.context.BootstrapWith(value=org.springframework.boot.test.context.SpringBootTestContextBootstrapper.class)
Find attached a very simple & minimal reproducer case.
Steps
Preparation
unzip spring-reproducer.zip
cd spring-reproducer
OK with 2.3.7.RELEASE
mvn clean verify
Failing with 2.4.3
mvn -Dspring-boot.version=2.4.3 clean verify
using this version of spring-boot the build fails showing the following details in the failsafe-report
-------------------------------------------------------------------------------
Test set: com.lectra.spring.ApplicationLoaderTestIT
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.136 s <<< FAILURE! - in com.lectra.spring.ApplicationLoaderTestIT
com.lectra.spring.ApplicationLoaderTestIT Time elapsed: 0.136 s <<< ERROR!
java.lang.IllegalStateException: Failed to find merged annotation for @org.springframework.test.context.BootstrapWith(value=org.springframework.boot.test.context.SpringBootTestContextBootstrapper.class)
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Maven Failsafe Plugin – Inclusions and Exclusions of Tests
If the test classes do not follow the default wildcard patterns, then override them by configuring the Failsafe Plugin and specify the tests ......
Read more >Stop spring boot from executing failsafe plugin - Stack Overflow
When I run mvn integration-test -PmyProfile , maven starts running the default failsafe execution mentioned in the spring dependency first. And ...
Read more >Spring Boot Maven Plugin Documentation
The Spring Boot Maven Plugin provides Spring Boot support in Apache Maven. It allows you to package executable jar or war archives, ...
Read more >Spring Boot Starter Parent - Javatpoint
The spring-boot-starter-parent specifies the default configuration for a host of plugins including maven-failsafe-plugin, maven-jar-plugin and ...
Read more >maven spring-boot-maven-plugin is highlighted in red if ...
But it should work without specifying the version. The version is already set in spring-boot-starter-parent. That is the purpose of this parent!
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It turns out that is indeed the case.
After some debugging and a follow-up brainstorming session with @wilkinsona, we’ve determined that this is effectively a duplicate of https://github.com/spring-projects/spring-boot/issues/6254.
The fact that you resorted to the following should have been an indicator that something was wrong with the classpath.
In a properly structured Spring Boot project, an empty
@SpringBootTest
declaration should suffice: Spring Boot Test will find your@SpringBootApplication
class automatically.The reason your Maven Failsafe configuration is not working is two-fold.
<property name="jdk.module.path" value="/path/to/project/target/MyApplication.jar"/>
.To fix problem # 1, you need to add the following to the
<configuration>
section of themaven-failsafe-plugin
:To fix problem # 2, you have some options
I went with option # 3 above and combined that with the first fix, ending up with the following in the
<configuration>
section of themaven-failsafe-plugin
.After that, both test classes pass with the Surefire and Failsafe plugins, respectively.
In light of that, I think this issue should be transferred to Spring Boot to improve the documentation.
p.s. @wilkinsona mentioned that these issues may not have manifested if the project’s POM inherited from the Spring Boot parent POM, but I’ll let him expound on that.
Thanks, @sbrannen.
spring-boot-starter-parent
configures some defaults for Failsafe. Specifically, it configures the<classesDirectory>
to be${project.build.outputDirectory}
. I think we should consider documenting this somewhere for the benefit of users whose Maven projects don’t usespring-boot-starter-parent
.