Spring Tool Suite
  1. Spring Tool Suite
  2. STS-1950

Gradle STS support: Test fails to run in IDE due to ClassNotFound even though Gradle Dependencies container shows the class to be on the classpath

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.7.0.RELEASE
    • Fix Version/s: 2.9.0.M1
    • Component/s: GRADLE
    • Labels:

      Description

      Project: Spring Social, a multi-module build
      Module effected: spring-social-web
      Test that fails with ClassNotFoundException: org.springframework.social.connect.web.ConnectSupportTest
      Class in error: Says "javax.servlet.http.HttpServletRequest" - despite the fact servlet-api-2.5.jar is a "Gradle Dependency" and the class is there.

      Somewhat unrelated, for some reason STS (2.7) is also not allowing me to run this class "as a unit test". I'm having to run it by selecting the src/test/java folder and running that folder.

      java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
      	at java.lang.ClassLoader.defineClass1(Native Method)
      	at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
      	at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
      	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
      	at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
      	at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
      	at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
      	at java.lang.Class.getDeclaredMethods0(Native Method)
      	at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
      	at java.lang.Class.getMethod0(Class.java:2670)
      	at java.lang.Class.getMethod(Class.java:1603)
      	at org.junit.internal.builders.SuiteMethodBuilder.hasSuiteMethod(SuiteMethodBuilder.java:20)
      	at org.junit.internal.builders.SuiteMethodBuilder.runnerForClass(SuiteMethodBuilder.java:13)
      	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
      	at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
      	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
      	at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
      	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
      	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
      	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
      	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
      Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest
      	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:306)
      	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
      	... 30 more
      

        Activity

        Hide
        Mauro Molinari added a comment -

        I suspect the nightly build I downloaded actually does have the fix because now all my JUnit launch configurations work as expected, thank you Kris

        Show
        Mauro Molinari added a comment - I suspect the nightly build I downloaded actually does have the fix because now all my JUnit launch configurations work as expected, thank you Kris
        Hide
        Kris De Volder (c) added a comment -

        Cool thanks for confirming. I'm glad we got this fixed. I think it was a serious issue with much potential to create problems for many users

        Don't know if STS-2190 could be related. But maybe I'll try to have a look at that issue later today.

        Show
        Kris De Volder (c) added a comment - Cool thanks for confirming. I'm glad we got this fixed. I think it was a serious issue with much potential to create problems for many users Don't know if STS-2190 could be related. But maybe I'll try to have a look at that issue later today.
        Hide
        Michael Brand added a comment -

        We're seeing this exact problem using an AspectJ compiler. JUnit works for projects that are not dependent on an AspectJ. But when we added AspectJ this problem appeared.

        We're using SpringSource version 2.9.0.201112091000-M1 and gradle-1.0-milestone-7. Do you have any suggestions for a resolution? Should we open a new defect or re-open this one?

        Show
        Michael Brand added a comment - We're seeing this exact problem using an AspectJ compiler. JUnit works for projects that are not dependent on an AspectJ. But when we added AspectJ this problem appeared. We're using SpringSource version 2.9.0.201112091000-M1 and gradle-1.0-milestone-7. Do you have any suggestions for a resolution? Should we open a new defect or re-open this one?
        Hide
        Mauro Molinari added a comment -

        Actually this problem was about the fact that the "Gradle Dependencies" library was not put in the runtime build path when an Eclipse launch was run (the JUnit launch, for instance, or even a plain Java Application launch), especially when dependencies between projects were involved.
        Since I updated to 2.9.0.x I've never seen this problem again.
        So, I think the AspectJ problem is something else, but I don't know anything about it, so Kris may be of more help here.

        Show
        Mauro Molinari added a comment - Actually this problem was about the fact that the "Gradle Dependencies" library was not put in the runtime build path when an Eclipse launch was run (the JUnit launch, for instance, or even a plain Java Application launch), especially when dependencies between projects were involved. Since I updated to 2.9.0.x I've never seen this problem again. So, I think the AspectJ problem is something else, but I don't know anything about it, so Kris may be of more help here.
        Hide
        Kris De Volder (c) added a comment -

        Hi Michael,

        It could be the problem is related/similar, but let's start with a 'clean' slate and open a new ticket.

        Michael, you think you could create some small test project that demonstrates the problem. That will help greatly in trying to reproduce and fix.

        Kris

        Show
        Kris De Volder (c) added a comment - Hi Michael, It could be the problem is related/similar, but let's start with a 'clean' slate and open a new ticket. Michael, you think you could create some small test project that demonstrates the problem. That will help greatly in trying to reproduce and fix. Kris

          People

          • Assignee:
            Kris De Volder (c)
            Reporter:
            Keith Donald
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              First Response Date: