maven scope

作者: lyc365happy | 来源:发表于2017-04-21 18:10 被阅读44次
  • 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.

相关文章

  • Maven Scope 作用说明

    Scope Maven中的scope有compile、test、runtime、provided、system,其...

  • 15分钟Maven

    Maven Scope provided - Dependencies that are required for...

  • maven scope

    compile默认就是compile。compile表示被依赖项目需要参与当前项目的编译,当然后续的测试,运行周期...

  • maven scope

    compile,缺省值,适用于所有阶段,会随着项目一起发布。compile is the default scop...

  • Maven scope

    说在最前面:理解事物需要看清它的边界。 dependency中的scope是用来指定依赖包的使用范围。 那么依赖包...

  • maven scope

    1)详解 对于scope=compile的情况(默认scope),也就是说这个项目在编译,测试,运行阶段都需要这个...

  • Maven Scope

    Maven Scope就是用来控制依赖和三种classpath(编译classpath,测试classpath、运...

  • Maven依赖中scope的含义

    Maven依赖中scope的含义 整理一下Maven中Scope的详细作用,都是抄的别人内容整理了一下。参考:ht...

  • Maven依赖中scope的含义

    Maven依赖中scope的含义 整理一下Maven中Scope的详细作用,都是抄的别人内容整理了一下。参考:ht...

  • Maven的配置、Spring初识

    一、Maven的web项目配置 1、pom.xml文件中scope标签 scope标签位于dependency标签...

网友评论

    本文标题:maven scope

    本文链接:https://www.haomeiwen.com/subject/xiadzttx.html