maven dependency scope
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:
compile
(default): This is the default scope. Dependencies with this scope are available at compile time and at runtime.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.runtime
: Dependencies with this scope are not needed for compilation, but are needed at runtime. They are not packaged with the application.test
: Dependencies with this scope are needed only for testing the application, and are not packaged with the application.system
: Dependencies with this scope are similar toprovided
, but you have to provide the JAR explicitly in thesystemPath
element of thedependency
element.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.