EN
Maven - difference between compile and provided scope
9 points
In this short article, we will answer the question: what is the difference between compile
and provided
scope
dependency during packaging JAR or WAR package?
Short answer:
compile
scope will cause embedding dependency into the output JAR/WAR package,provided
scope will cause the dependency is used only during compilation, and later if the dependency will be required should be provided by an environment, e.g. Tomcat server with embedded libraries, Lombok library when maven preprocessing configuration is used, etc.
Maven documentation:
<scope> | Description |
compile | This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects. |
provided | This is much like compile , but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. A dependency with this scope is added to the classpath used for compilation and test, but not the runtime classpath. It is not transitive. |