Languages
[Edit]
EN

Maven - difference between compile and provided scope

9 points
Created by:
Vadim-Kotiv
414

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
compileThis 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.
providedThis 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.

 

Sources

  1. Dependency Scope - Maven Docs

Alternative titles

  1. Maven - compile vs provided scope
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join