11

I've just upgraded my projects to use Spring Boot 2.1.0 (before it was 2.0.x) and i have compilation WARNINGS:

[WARNING] Cannot find annotation method 'value()' in type 'org.junit.jupiter.api.extension.ExtendWith': class file for org.junit.jupiter.api.extension.ExtendWith not found

I can add dependency org.junit.jupiter / junit-jupiter-api to solve the warning, but I feel it's a 'hack'.

I don't want to see that warning (especially that my projects treat warnings like errors) and I don't want to pollute my projects with unnecessary dependencies.

i'm using Maven, but i can see someone had the same problem with Gradle https://www.reddit.com/r/java/comments/9sogxf/spring_boot_210_released_now_with_java_11_support/

razor
  • 2,727
  • 6
  • 33
  • 45
  • 2
    Can you add the POM file to the question? – Boris Nov 15 '18 at 12:49
  • Are you using maven/gradle/...? – T A Nov 15 '18 at 12:50
  • Maven, and i've only changed spring-boot version.| do you want to see 'effective POM' or just for a project? (it'll be hard, as versions are managed by spring and my parent POM) – razor Nov 15 '18 at 12:52
  • someone had the same problem (using gradle) so i guess it;s not a gradle/maven problem https://www.reddit.com/r/java/comments/9sogxf/spring_boot_210_released_now_with_java_11_support/ – razor Nov 15 '18 at 12:54
  • 1
    If you are upgrading your spring boot jar version, then I think you should consider upgrading the versions of the dependencies as well wherever required to maintain backwards compatibility. This would help in the longer run. https://mvnrepository.com/artifact/org.springframework.boot/spring-boot/2.1.0.RELEASE – A_C Nov 15 '18 at 12:57
  • Have you tried excluding JUnit5 from your Spring Boot dependencies in your pom? – T A Nov 15 '18 at 12:58
  • i've tried few artifacts, but i don't know which one exactly. well, i think the problem is that Spring expects some JUnit5 artifacts (Api one), but i don't have ANY junit artifacts in 'effective POM' – razor Nov 15 '18 at 13:07
  • What version of Java are you using? I’ve only ever seen this warning with old versions of Java 8. – Andy Wilkinson Nov 15 '18 at 19:48
  • openjdk 1.8.0._181 – razor Nov 16 '18 at 10:30
  • 3
    The problem is that for example `@DataJpaTest` or `@SpringBootTest` annotations are annotated with `@ExtendWith`, which is part of JUnit 5, so it seems you have to JUnit 5 API in the classpath even if you are not using it. – DAN Dec 06 '18 at 13:01

2 Answers2

9

If you add the org.junit.jupiter:junit-jupiter-api dependency to your project the warning will go away. It shouldn't hurt, because it's only API jar and only in test scope.

DAN
  • 507
  • 1
  • 7
  • 16
1

If you are using the @SpringBootTest to set classes=:

@SpringBootTest(classes = {
        MyAutoConfiguration.class,
        MyAutoConfigurationIntegrationTest.TestContextConfiguration.class
    })

the answer is alluded to in its api documentation:

Annotation that can be specified on a test class that runs Spring Boot based tests. Provides the following features over and above the regular Spring TestContext Framework:

Uses SpringBootContextLoader as the default ContextLoader when no specific @ContextConfiguration(loader=...) is defined.

Automatically searches for a @SpringBootConfiguration when nested @Configuration is not used, and no explicit classes are specified.

You can use @ContextConfiguration which does not depend on Junit5's @ExtendsWith:

@RunWith(SpringRunner.class)
@ContextConfiguration(loader = SpringBootContextLoader.class,
    classes = {
        MyAutoConfiguration.class,
        MyAutoConfigurationIntegrationTest.TestContextConfiguration.class
    })
Alun
  • 541
  • 6
  • 16