原帖地址: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. [AngularJS] Javascript scope and AngularJS $scope

    Scope resolution of our Angular documents works exactly the same way scope resolution works in plain ...

  2. mysql online ddl2

          大家知道,互联网业务是典型的OLTP(online transaction process)应用,这种应用访问数据库的特点是大量的短事务高并发运行.因此任何限制高并发的动作都是不可接受的, ...

  3. LINUX 文件系统如何存储文件 图解

    http://zhuqiuxu.iteye.com/blog/2116023 http://zhuqiuxu.iteye.com/blog/2116168 理解Inode要从文件说起,文件存储在硬盘上 ...

  4. java 技术体系

  5. 如何用jquery操作table的方法

    今天我在做你约我吧交友www.niyuewo.com网项目时遇到一个问题,就是如何用qjuery控制table的添加.编辑与删除,经过网上查资料发现用jquery很容易实现,在此整理下来供大家参考: ...

  6. Java_InvokeAll_又返回值_多个线程同时执行,取消超时线程

    package com.demo.test4; import java.util.ArrayList; import java.util.List; import java.util.concurre ...

  7. OpenCV之邻域运算之最值滤波

    写了一段小程序,分享给大家! //==================================================================== // 作者 : quarry ...

  8. IE7下position:relative的问题

    如果在IE7中使用position:relative属性,需要在该元素的容器上,同时给予position:relative属性.

  9. Shlwapi.h Shlwapi.dll 动态库

    Windows中有一个Shlwapi.dll文件,包含了大量的Windows字符串处理方法,这些方法,在通常的程序应用中,经常会用到,有一部分处理方法,在CRuntime中也存在,但不方便使用.有一部 ...

  10. UITableViewCell高度自适应探索--AutoLayout结合Frame

    UITableViewCell高度自适应探索--UITableView+FDTemplateLayoutCell地址: http://www.jianshu.com/p/7839e3a273a6UIT ...