官方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里

       <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
  • runtime
    表示dependency不作用在编译时,但会作用在运行和测试时
  • test
    表示dependency作用在测试时,不作用在运行时。
  • system
    跟provided 相似,但是在系统中要以外部JAR包的形式提供,maven不会在repository查找它。 例如:

  

<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>
  • 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用法

    原帖地址:http://uule.iteye.com/blog/2087485 官方API描述 Dependency scope 是用来限制Dependency的作用范围的, 影响maven项目在各个 ...

  2. 15) maven dependency scope

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

  3. Maven的dependency scope属性

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

  4. Maven学习----Dependency scope

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

  5. Dependency Scope

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

  6. Maven依赖Scope标签用法

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

  7. maven中scope属性的

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

  8. maven中scope

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

  9. Maven错误Failed to read artifact descriptor for xxx:jar 和 missing artifact maven dependency

    可参考:http://stackoverflow.com/questions/6111408/maven2-missing-artifact-but-jars-are-in-place http:// ...

随机推荐

  1. [NOI 2017]蚯蚓排队

    Description 题库链接 蚯蚓幼儿园有 \(n\) 只蚯蚓.幼儿园园长神刀手为了管理方便,时常让这些蚯蚓们列队表演. 所有蚯蚓用从 \(1\) 到 \(n\) 的连续正整数编号.每只蚯蚓的长度 ...

  2. Linux 命令行下光标移动快捷键

    常用的快捷键: Ctrl + u 删除光标之前到行首的字符 Ctrl + k 删除光标之后到行尾的字符 Ctrl + a 光标移动到行首 Ctrl + e 光标移动到行尾 Ctrl + l 清屏 Al ...

  3. C# 类相同属性赋值

    做项目时偶尔B类赋值给A类,碰巧A和B类型很多属性字段名是一样的,或者只是大小写不一样,这是可以利用泛型,反射来写一个自动化赋值的方法. 下面方法不考虑大小写不一样的情况,如果要考虑,可以使用字符串方 ...

  4. LeetCode算法笔记目录

    贪心算法: LeetCode翻转矩阵后的得分-Python3<六> LeetCode根据身高重建队列-Python3<七> LeetCode 任务调度器-Python3< ...

  5. idea/ecipse中使用maven集成springmvc相关jar包时候,出错:java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet

    参考stackoverflow:https://stackoverflow.com/questions/11227395/java-lang-classnotfoundexception-org-sp ...

  6. NULL 和 0

    Question: What is the difference from NULL and "0"? Example: return NULL; return 0; Answer ...

  7. 再也不用担心面试官问你HashCode和equals了

    结论 如果两个对象相等,则hashcode()必须相等. 如果两个对象相等,a.equals(b)==b.equals(a)==true 如果两个对象有相同的hashcode值,他们也不一定是相等的. ...

  8. js 前端有消息了 声音提示给用户

    前言:工作中有需求,在数据变更有变更时采用声音提示给用户,这里记录一下.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9936180.html 网站地址:我的个 ...

  9. netty 基础

    Netty是一个高性能.异步事件驱动的NIO框架,提供了对TCP.UDP和文件传输的支持,作为一个异步NIO框架,Netty的所有IO操作都是异步非阻塞的,通过Future-Listener机制,用户 ...

  10. Python 练习:简单的购物车

    salary = int(input("Please input your salary: ")) msg = ''' 1. iphone6s 5800 2. mac book 9 ...