maven 有6个scope类型,下面简单总结备忘下

<dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>2.4</version><scope>provided</scope>
</dependency>

maven官方描述

Dependency Scope
Dependency scope is used to limit the transitivity of a depedency, and also to affect the classpath used for various build tasks.

There are 6 scopes available:

compile
This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects. 
provided
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive. 
runtime
This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath. 
test
This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases. 
system
This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository. 
import (only available in Maven 2.0.9 or later)
This scope is only used on a dependency of type pom in the <dependencyManagement> section. It indicates that the specified POM should be replaced with the dependencies in that POM's <dependencyManagement> section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.

------------------------------------------------------------------------------------------------------------------------------------

翻译下(以下内容载自:http://acooly.iteye.com/blog/1788890)

1.compile

编译范围,默认scope,在工程环境的classpath(编译环境)和打包(如果是WAR包,会包含在WAR包中)时候都有效。

2.provided

容器或JDK已提供范围,表示该依赖包已经由目标容器(如tomcat)和JDK提供,只在编译的classpath中加载和使用,打包的时候不会包含在目标包中。最常见的是j2ee规范相关的servlet-api和jsp-api等jar包,一般由servlet容器提供,无需在打包到war包中,如果不配置为provided,把这些包打包到工程war包中,在tomcat6以上版本会出现冲突无法正常运行程序(版本不符的情况)。

3.runtime

一般是运行和测试环境使用,编译时候不用加入classpath,打包时候会打包到目标包中。一般是通过动态加载或接口反射加载的情况比较多。也就是说程序只使用了接口,具体的时候可能有多个,运行时通过配置文件或jar包扫描动态加载的情况。典型的包括:JDBC驱动等。

4.test

测试范围,一般是单元测试场景使用,在编译环境加入classpath,但打包时不会加入,如junit等。

5.system

系统范围,与provided类似,只是标记为该scope的依赖包需要明确指定基于文件系统的jar包路径。因为需要通过systemPath指定本地jar文件路径,所以该scope是不推荐的。如果是基于组织的,一般会建立本地镜像,会把本地的或组织的基础组件加入本地镜像管理,避过使用该scope的情况。

实践:

  • provided是没有传递性的,也就是说,如果你依赖的某个jar包,它的某个jar的范围是provided,那么该jar不会在你的工程中依靠jar依赖传递加入到你的工程中。
  • provided具有继承性,上面的情况,如果需要统一配置一个组织的通用的provided依赖,可以使用parent,然后在所有工程中继承。

如何使用Maven scope相关推荐

  1. maven scope/site/effective-pom/assembly

    point1:<dependency>依赖范围 <scope/>中进行配置 --compile:默认配置,对编译/测试/运行三种都有效. --test:只对测试有效. --ru ...

  2. maven scope 属性和生命周期

    2019独角兽企业重金招聘Python工程师标准>>> maven的dependency参数 scope的分类 1.compile:默认值 他表示被依赖项目需要参与当前项目的编译,还 ...

  3. Maven Scope取值的含义

    maven依赖关系中Scope的作用 Dependency Scope 在POM 4中,<dependency>中还引入了<scope>,它主要管理依赖的部署.目前<sc ...

  4. maven scope使用和理解

    在Maven的依赖管理中,经常会用到依赖的scope设置.这里整理下各种scope的使用场景和说明,以及在使用中的实践心得. scope的使用场景和说明 1.compile 编译范围,默认scope, ...

  5. maven scope 的作用

    一: 1.Maven中的依赖作用范围概述 Maven中使用 scope 来指定当前包的依赖范围和依赖的传递性.常见的可选值有:compile, provided, runtime, test, sys ...

  6. Maven Scope 讲解

    依赖的Scope scope定义了类包在项目的使用阶段.项目阶段包括: 编译,运行,测试和发布. 分类说明 compile 默认scope为compile,表示为当前依赖参与项目的编译.测试和运行阶段 ...

  7. Maven scope作用

    Maven依赖中scope标签 介绍 compile runtime test provided system import 依赖传递 介绍 scope元素的主要作用就是控制 dependency 元 ...

  8. Maven scope 依赖范围详解

    Maven的生命周期存在编译.测试.运行.打包这些过程,那么显然有些依赖只用于测试(test),比如 junit : 有些依赖编译用不到,只有运行的时候才能用到( runtime ),比如 mysql ...

  9. maven scope含义的说明

    依赖范围控制哪些依赖在哪些classpath 中可用,哪些依赖包含在一个应用中.让我们详细看一下每一种范围: compile (编译范围) compile是默认的范围:如果没有提供一个范围,那该依赖的 ...

最新文章

  1. 第十六届智能车竞赛比赛进行中 - 参赛队员提出的问题
  2. android 蓝牙通讯测试工具,Android Bluetooth 学习(2)应用层实现蓝牙设备查找、tcp_ip通信...
  3. 在Ubuntu上安装JDK、Ant、Jmeter和Jenkins
  4. textarea文本域
  5. 交通流理论1——发展阶段
  6. 【好文】敏捷中国十八年目睹之怪现状
  7. windows server 2008安装配置web服务器
  8. C#WinForm程序 窗口不在任务栏显示的处理方法
  9. 人生苦短python作伴_人生苦短,我用python
  10. django mysql sql语句_Django中使用mysql数据库并使用原生sql语句操作
  11. Johnson–Lindenstrauss Lemma
  12. Java——将汉字转为汉语拼音工具类
  13. 电商实时交易风控系统
  14. HDU1411求四面体体积
  15. 思科ASA防火墙: 接口配置名称 安全等级 acl防控列表
  16. 《遥感图像处理笔记》第1章
  17. 分享CFA一级通过标准!
  18. JavaWeb笔试题
  19. 自然顺序假设(The Natural Order Hypothesis)
  20. androidstudio图片居中_[Android]Android 布局中如何让图片和文字居中显示?

热门文章

  1. 调试U-Boot笔记(一)
  2. 从Java视角理解伪共享(False Sharing)
  3. 在SharePoint2007中创建站点一:相关服务的启动
  4. ping命令时常碰到的问题
  5. 关于301跳转的多种办法
  6. Ruby on Rails 生成指定版本的 Rails 项目
  7. MHA选择主库源码解析
  8. LeetCode Number Complement
  9. 中国程序员如何去 Facebook 工作?
  10. Android使用 SO 库时要注意的一些问题