8

I reordered my dependencies in build.gradle in alphabetical order, after which I quickly noticed that my Spring application no longer works properly (it halts with message java.lang.NoSuchMethodError: javax.servlet.ServletContext.getClassLoader() on start up). If I move the undertow dependency from the middle to the top, then everything works fine as before.

How does dependency ordering affect the way the application is run? What is the suggested order?

David Frank
  • 5,918
  • 8
  • 28
  • 43
  • On a related note, using Grails 3.3.1, if you alphabetize these lines in build.gradle: apply plugin: "eclipse" | apply plugin: "idea" | apply plugin: "war" | apply plugin: "org.grails.grails-web" | apply plugin: "asset-pipeline" | apply plugin: "org.grails.grails-gsp" then deploy the app to Tomcat, it fails with the message: javax.servlet.ServletException: Could not resolve view with name '/index' in servlet with name 'grailsDispatcherServlet' – Rob Stoecklein Oct 27 '17 at 17:06

1 Answers1

4

It has an influence on the classpath of the application. There is probably an older version of Servlet specification above undertown dependency. This answer explains why this particular error occurs for older Servlet specification.

Community
  • 1
  • 1
Nicolas Henneaux
  • 11,507
  • 11
  • 57
  • 82
  • Does it mean that dependencies that are on top take precedence over the below ones? What's the case with transitional dependencies of above and below dependencies? – David Frank Aug 03 '16 at 17:00
  • Yes, the first class matching the FQN is loaded in the order of the classpath declaration (which is build using the dependencies order). For transitional dependencies, it is probably added after the parent dependencies in the classpath. You should increase logging to see the classpath (-cp option in java command line). – Nicolas Henneaux Aug 03 '16 at 18:28