-
compile,缺省值,适用于所有阶段,会随着项目一起发布。
compile is the default scope; all dependencies are compile-scoped if a scope is not supplied.compile dependencies are available in all classpaths, and they are packaged. -
provided,类似compile,期望JDK、容器或使用者会提供这个依赖。如servlet.jar。
provided dependencies are used when you expect the JDK or a container to provide them. For example, if you were developing a web application, you would need the Servlet API available on
the compile classpath to compile a servlet, but you wouldn’t want to include the Servlet API in the packaged WAR; the Servlet API JAR is supplied by your application server or servlet container.
provided dependencies are available on the compilation classpath (not runtime). They are not transitive, nor are they packaged. -
runtime,只在运行时使用,如JDBC驱动,适用运行和[测试]阶段。
runtime dependencies are required to execute and test the system, but they are not required for compilation. For example, you may need a JDBC API JAR at compile time and the JDBC driver implementation only at runtime. -
test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。
test-scoped dependencies are not required during the normal operation of an application, and they are available only during test compilation and execution phases. -
system,类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找它。
The system scope is similar to provided except that you have to provide an explicit path to the JAR on the local file system. This is intended to allow compilation against native objects that may
be part of the system libraries. The artifact is assumed to always be available and is not looked up in a repository. If you declare the scope to be system, you must also provide the systemPath
element. Note that this scope is not recommended (you should always try to reference dependencies
in a public or custom Maven repository).
The second dependency is a test-scoped dependency on JUnit. You would use a testscoped dependency when you need to reference this library only during testing.
The last dependency in Project Dependencies is a dependency on the Servlet 2.4 API. The last dependency is scoped as a provided dependency. You would use a provided scope when the application you are developing needs a library for compilation and testing, but this library is supplied by a container at runtime.
网友评论