1. enumerate the meaning of each attribute value
- Compile, default value. It applies to all stages and is packaged into the project.
- Provided, similar to compile, expects JDK, container, or user to provide this dependency.
- Runtime, used only at runtime, such as the JDBC driver, applicable to the running and testing stages.
- Test, which is only used for testing and is used to compile and run the test code. Will not be released along with the project.
- System, similar to provided, must explicitly provide jar containing dependencies, MAVEN will not find it in repository.
2. attribute values of other types are easy to understand. Here we will compare the differences between compile and runtime:
(1) describe a simple example: module A depends on X, and the scope value of X is runtime;
(2) If another Module B depends on a, B will not depend on X during compilation (there will be no problems during compilation );
If the scope of X is set to compile, it indicates that at the time of compilation, B needs to display the class related to calling X. JDBC is the most common setting of Maven dependency as the dependency of runtime, the main reason is that the configuration of the driver class in JDBC uses the reflection mechanism to configure class-name in the configuration file;
Maven scope Attribute Value Setting meaning