原帖地址:http://uule.iteye.com/blog/2087485

官方API描述

Dependency scope 是用来限制Dependency的作用范围的, 影响maven项目在各个生命周期时导入的package的状态。

自从2.0.9后,新增了1种,现在有了6种scope:

  • compile
    默认的scope,表示 dependency 都可以在生命周期中使用。而且,这些dependencies 会传递到依赖的项目中。
  • provided
    跟compile相似,但是表明了dependency 由JDK或者容器提供,例如Servlet AP和一些Java EE APIs。这个scope 只能作用在编译和测试时,同时没有传递性。
  • 使用这个时,不会将包打入本项目中,只是依赖过来。   
  • 使用默认或其他时,会将依赖的项目打成jar包,放入本项目的Lib里
  • 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.
    1. <!-- Servlet -->
    2. <dependency>
    3. <groupId>javax.servlet</groupId>
    4. <artifactId>servlet-api</artifactId>
    5. <version>2.5</version>
    6. <scope>provided</scope>
    7. </dependency>
    8. <dependency>
    9. <groupId>javax.servlet.jsp</groupId>
    10. <artifactId>jsp-api</artifactId>
    11. <version>2.1</version>
    12. <scope>provided</scope>
    13. </dependency>
  • runtime
    表示dependency不作用在编译时,但会作用在运行和测试时
  • test
    表示dependency作用在测试时,不作用在运行时。
  • system
    跟provided 相似,但是在系统中要以外部JAR包的形式提供,maven不会在repository查找它。 例如:

<project>
...
<dependencies>
  <dependency>
   <groupId>javax.sql</groupId>
   <artifactId>jdbc-stdext</artifactId>
   <version>2.0</version>
   <scope>system</scope>
   <systemPath>${java.home}/lib/rt.jar</systemPath>
  </dependency>
</dependencies>
...
</project>

  • import (Maven 2.0.9 之后新增)
    它只使用在<dependencyManagement>中,表示从其它的pom中导入dependency的配置,例如:    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.

<project>

<modelVersion>4.0.0</modelVersion>

<groupId>maven</groupId>

<artifactId>B</artifactId>

<packaging>pom</packaging>

<name>B</name>

<version>1.0</version>

<dependencyManagement>

<dependencies>

<dependency>

<groupId>maven</groupId>

<artifactId>A</artifactId>

<version>1.0</version>

<type>pom</type>

<scope>import</scope>

</dependency>

<dependency>

<groupId>test</groupId>

<artifactId>d</artifactId>

<version>1.0</version>

</dependency>

</dependencies>

</dependencyManagement>

</project>

B项目导入A项目中的包配置

Maven Dependency Scope用法的更多相关文章

  1. Maven Dependency Scope

     官方API描述 Dependency scope 是用来限制Dependency的作用范围的, 影响maven项目在各个生命周期时导入的package的状态. 自从2.0.9后,新增了1种,现在有了 ...

  2. 15) maven dependency scope

    Dependency Scope Dependency scope is used to limit the transitivity of a dependency, and also to aff ...

  3. Maven pom文件中dependency scope用法

    在Maven中依赖的域有:compile.provided.runtime.system.test.import 一.compile(默认) 当依赖的scope为compile的时候,那么当前这个依赖 ...

  4. Maven依赖Scope标签用法

    在一个maven项目中,如果存在编译需要而发布不需要的jar包,可以用scope标签,值设为provided.如下: <dependency>            <groupId ...

  5. Maven的dependency scope属性

    官方地址:https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependen ...

  6. Maven学习----Dependency scope

    首先官网API 2.09版本之后,有6中scope. Dependency scope 用来限制依赖的作用范围,同时也作用于各种编译路径类路径,下面详细说明这六种路径: compile这是默认范围,C ...

  7. Dependency Scope

    Dependency Scope <dependency>中还引入了<scope>,它主要管理依赖的部署.目前<scope>可以使用5个值: * compile,缺 ...

  8. maven中scope属性的

    Dependency Scope 在POM 4中,<dependency>中还引入了<scope>,它主要管理依赖的部署.目前<scope>可以使用5个值: * c ...

  9. maven中scope

    scope maven中scope的默认值是compilescope的分类1)compile 默认是compile.compile表示被依赖项目需要参与当前项目的编译,包括后续的测试,运行周期也参与其 ...

随机推荐

  1. Android源代码下载方法具体解释

    作者:张星 相信非常多下载过内核的人都对这个非常熟悉 git clone git://android.git.kernel.org/kernel/common.git kernel 可是这是在曾经,如 ...

  2. LINUX 内核文档地址

    Linux的man很强大,该手册分成很多section,使用man时可以指定不同的section来浏览,各个section意义如下: 1 - commands2 - system calls3 - l ...

  3. SQL Server2008创建约束图解 转

    转自 http://www.cnblogs.com/longhs/p/3670307.html SQLServer 中有五种约束, Primary Key 约束. Foreign Key 约束. Un ...

  4. JMX笔记(一)

    上篇 JMX初体验 使用HtmlAdaptorServer提供的界面实现了调用MBean,除此之外,还可以使用rmi方式连接调用MBeanServer 要连接,自然要有url:service:jmx: ...

  5. 怎么删除远程登录连接的ip

    通过远程桌面可以登录到远程电脑上进行相应的操作,在登录过后会在本地电脑上留下登录过的IP以及登录用户名相关信息,可能会给远程的电脑带来安全隐患,下面介绍一下清除远程桌面历史记录的方法. 1.删除我的文 ...

  6. LeetCode 338

    Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the ...

  7. 关于Excle中的VLookUp的函数的使用

    VLookUp函数的使用,VLookUp中的V是垂直的(vertical)意思,此外与此相类似的函数还有HLOOKUP(Horizonal水平的)意思. 下面主要谈谈VLookUp的使用方法. VLo ...

  8. nmap命令-----高级用法

    探测主机存活常用方式 (1)-sP :进行ping扫描 打印出对ping扫描做出响应的主机,不做进一步测试(如端口扫描或者操作系统探测):  下面去扫描10.0.3.0/24这个网段的的主机 nmap ...

  9. ubuntu(16.04.01)学习-day2

    1.建立硬链接: ln main.c mainsoft 2.建立软链接:ln -s main.c soft 3.对文档进行统计 wc main.c返回行.单词数和字符数 4.查看相应命令的描述 wha ...

  10. 【转】Log4.NET mark

    C#通过log4net进行异常记录 C#中异常的记录也有一个模板,就是log4net.多的就不说了直接看怎么用的吧. 1.引用log4net.dll. 2.实现log4net的方法. public c ...