-
Notifications
You must be signed in to change notification settings - Fork 41.1k
NoClassDefFoundError when using JUnit to test a Gradle 7.6.x app that depends on spring-boot-actuator-autoconfigure but not on org.junit.platform:junit-platform-launcher #43340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
duplicates #43339 |
I am running into the same issues as the original post here when upgrading from Spring Boot 3.3.+ to Spring Boot 3.4.0. We have approx. 100 projects all building with Gradle 7.6.1, and see the above error in roughly 1/3 of the projects where tests pass with Spring Boot 3.3.5. The other 2/3 see to run without issue. We're working on figuring out what distinguishes the failing projects from the working projects and will put together a small sample app if we can. As recommended in the StackOverflow post, we can add the dependency org.junit.platform:junit-platform-launcher to our failing projects and get tests to pass. We have also noticed that Spring Initializer has added the dependency to all Gradle based projects by default: spring-io/initializr#1476. I've left a comment there, but Ill ask the question here as well to try to get some traction on it: is the expectation that all Gradle based Spring Boot projects that use JUnit should include this dependency? If not all projects, what do we need to look for to know whether we need to add the dependency or not? If the answers to these questions is that the dependency is now expected, I think at the least that it would benefit the community if a note was added to the Migration Guide about the expectation and pushed under this ticket |
No.
The dependency is needed if you're using Gradle 8.3 or later, you're not using test suites, and you do not want to see a warning about the "automatic loading of test framework implementation dependencies" being deprecated. See https://docs.gradle.org/8.3/userguide/upgrading_version_8.html#test_framework_implementation_dependencies for further details. |
I can recreate this with Gradle 7.6.4. I used Spring Initializr to create the demo with Spring Boot 3.4.0. I then updated the build.gradle. to remove the
Should we be adding the |
I’m not sure that I understand what you’ve described. Please share the project that fails with a |
You can find the example at spring-boot-issue-43340. These were the steps I took to create my project that recreates the ClassNotFoundException
If the project is updated to use Gradle 8.11.1, I do not see the exception. We are using Gradle 7.6.4 and have these dependencies. Would like to know if the workaround is to explicitly add the junit-platform-launcher dependency? |
Thanks very much, @stephsmithnc. That sample has helped me to identify the root cause of the problem. The problem's caused by This sort of problem is exactly what Gradle 8 seeks to avoid by deprecating support for automatically loading test implementation classes. We'll discuss this as a team, but a reasonable workaround for now is to declare a dependency on |
I've got a branch that "fixes" this by migrating from a Flagging to see if the team think we should apply the "fix" or document the suggested workaround. |
With the I wonder if we could hook something in using If |
This doesn't work as it's I think we should revert our workaround in favor of an enhancement request for OpenTelemetry to add some testing support to |
I think I'd prefer to keep the existing code and document the fix for Gradle users. The existing code works for IDEs, modern Gradle and Maven and fixes an issue that's pretty hard to discover. At least the Gradle failure is easy to Google. |
I've opened https://github.com/spring-projects/spring-boot-release-verification/issues/3 so that we can catch this sort of problem during release verification. |
Many thanks again. |
Hello,
During the spring boot upgrade 3.4.0 i am getting below error which is actually working fine with 3.3.6.
Could someone pls help me to sort out the issue.
The text was updated successfully, but these errors were encountered: