Exclude servlet-api from test scope Maven

后端 未结 8 945
刺人心
刺人心 2021-02-13 04:43

I have the following dependency in my pom.xml so that my IDE (IntelliJ) has the servlet-api classes available during compilation, but not provided in the build.



        
相关标签:
8条回答
  • 2021-02-13 05:17

    For me same error came. I found old version of Servlet (2.5) existed in my path along with servlet 3.0. Once i remove(exclude) old version my issue solved.

    0 讨论(0)
  • 2021-02-13 05:22

    I just had this problem myself and wanted to share it:

    • Dependency on javax.servlet:servlet-api:3.0-alpha-1, with scope provided, so that it does not interfere with the container that my WAR is ultimately deployed onto
    • Dependency on org.eclipse.jetty:jetty-webapp, with scope test, so that I can run Jetty Server as part of my unit tests
    • Subsequently a transitive dependency on org.eclipse.jetty.orbit:javax.servlet:3.0.0.v201112011016, needed by jetty-webapp

    Exclusion of jetty.orbit:javax.servlet is no option (for me) because Jetty Server needed a javax.servlet.HttpConstraintElement that's not offered by javax.servlet:servlet-api:3.0-alpha-1. I ended up doing this:

    1. Remove the dependency on javax.servlet:servlet-api
    2. Explicitly add the dependency on jetty.orbit:javax.servlet, with scope provided, hence fully replacing javax.servlet:servlet-api

    I don't know what the deal is with the HttpConstraintElement that it needed; perhaps it'll be available in future versions of javax.servlet:servlet-api, which sorta feels to be a preferable dependency over Jetty's implementation of the same.

    Edit:

    By the way, the problem got introduced by me by fiddling with the configuration of a plugin that automatically formats POM files. It reordered dependencies and as such works against the solution of another poster to reorder the POM file. In my vast Maven experience: if you're "dependent" on the order of your dependencies, that's a major smell.

    0 讨论(0)
提交回复
热议问题