Uploaded image for project: 'Maven Surefire'
  1. Maven Surefire
  2. SUREFIRE-708

Test-classified but compile-scoped dependency causes NoClassDefFoundError: org/junit/runner/notification/RunListener

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Incomplete
    • 2.7.2
    • None
    • None

    Description

      I have a real-world project which has a test-classified third-party dependency that is (out of necessity) compile-scoped rather then test-scoped (as the test-JAR unfortunately contains classes also useful outside of a testing context). This constellation causes the maven-surefire-plugin to fail with a NoClassDefFoundError, thus effectively preventing the project from being build:

      java.lang.NoClassDefFoundError: org/junit/runner/notification/RunListener
      at java.lang.Class.getDeclaredConstructors0(Native Method)
      at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
      at java.lang.Class.getConstructor0(Class.java:2699)
      at java.lang.Class.getConstructor(Class.java:1657)
      at org.apache.maven.surefire.util.ReflectionUtils.getConstructor(ReflectionUtils.java:76)
      at org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:129)
      at org.apache.maven.surefire.booter.SurefireReflector.instantiateProvider(SurefireReflector.java:198)
      at org.apache.maven.surefire.booter.ProviderFactory.createProvider(ProviderFactory.java:72)
      at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:146)
      at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
      at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
      Caused by: java.lang.ClassNotFoundException: org.junit.runner.notification.RunListener
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
      at org.apache.maven.surefire.booter.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:93)
      ... 11 more

      Attached is a minimal Maven project (just the POM; whether there are test sources present doesn't change the outcome) that reproduces this problem.

      Attachments

        1. pom.xml
          1 kB
          Andreas Sewe

        Activity

          People

            Unassigned Unassigned
            sewe Andreas Sewe
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: