maven dependency scope

www‮igi.‬ftidea.com

In Maven, the dependency element is used to declare a dependency on an external library. The scope attribute of the dependency element is used to indicate the visibility of the dependency to various stages of the Maven build process. Here are the different values of the scope attribute and what they mean:

  1. compile (default): This is the default scope. Dependencies with this scope are available at compile time and at runtime.

  2. provided: Dependencies with this scope are provided by the JDK or the container in which the application is deployed. They are available at compile time, but not packaged with the application.

  3. runtime: Dependencies with this scope are not needed for compilation, but are needed at runtime. They are not packaged with the application.

  4. test: Dependencies with this scope are needed only for testing the application, and are not packaged with the application.

  5. system: Dependencies with this scope are similar to provided, but you have to provide the JAR explicitly in the systemPath element of the dependency element.

  6. import: Dependencies with this scope are used only to import the dependencies of another project.

Using the appropriate scope attribute can help you manage your project's dependencies more effectively and avoid dependency conflicts or unnecessary dependencies in the final application package.