原帖地址: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. ios开发——实用技术篇Swift篇&系统声音

    系统声音 // MARK: - 系统声音 /*----- 系统声音 ------*/ @IBAction func systemSound() { //建立的SystemSoundID对象 var s ...

  2. yii2 rbac 设计

    tbl_auth_item 根据type存储认证项目...role.task.operation 游客... 不能操作任何模块 普通用户 ..biz_rule..需要登录 只有这里返回true,才能进 ...

  3. 1085. Perfect Sequence (25)

    the problem is from PAT,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1085 At first ...

  4. oracle_partition sample_simple

    一:范围分区 就是根据数据库表中某一字段的值的范围来划分分区,例如: create table graderecord ( sno varchar2(10), sname varchar2(20), ...

  5. HDU 4279 - Number

    2012年天津赛区网赛的题目,想了好久,也没能想出来 还是小杰思路敏捷,给我讲解了一番,才让我把这个题做出来 f(x)=x-phi(x)(1——x与x互素个数)-g(x)(x的因子个数)+1 其中g( ...

  6. String StringBuilder以及StringBuffer

    例一:[看了威哥视频,下面更好理解] package sunjava; public class String_test { public static void main(String[] args ...

  7. Josephina and RPG

    Josephina and RPG Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. iOS 数据类型

    标签: 数据类型 1.Objective-C数据类型可以分为:基本数据类型.对象数据类型和id类型. 2.基本数据类型有:int.float.double和char类型. 3.对象类型就是类或协议所声 ...

  9. ArcGIS Server 10.2 实战(四)格栅动态配色服务

    当你的地理处理服务输出的是格栅,那个不可避免地需要为格栅的各类型数据添加不同色彩进行区分,而默认时格栅的色彩是随机的,或者固定死一套着色方案是也显得不够人性化,难以满足多样的客户需求,下面谈谈如何解决 ...

  10. Adobe Edge Animate –弹性的方块-使用tweenmax缓动效果

    Adobe Edge Animate –弹性的方块-使用tweenmax缓动效果 版权声明: 本文版权属于 北京联友天下科技发展有限公司. 转载的时候请注明版权和原文地址. 此前有Edge爱好者提出一 ...