Maven的核心笔记(5)maven的依赖范围

来源:互联网 发布:sql开发工程师招聘 编辑:程序博客网 时间:2024/06/05 15:14
  • 1.依赖的范围:
    • 项目的三种classpath:编译、测试、运行

<dependencies>    <dependency>    <groupId>junit</groupId>    <artifactId>junit</artifactId>    <version>3.8.1</version>    <scope>test</scope>    </dependency></dependencies>//表示Junit依赖范围是test,表明:junnit只存在测试的范围。
  • 2.maven提供了6种scope
Compile:默认的范围,编译、测试、运行的classpath都有效Provided:编译、测试有效,最后运行的时候不会被加入Runtime:测试、运行有效Test:仅测试有效System:与本机系统相关联,编译测试有效,但是可移植性差Import:导入的依赖范围,它只是用在dependencyManagemet中,表示从其他的pom中导入dependency的配置。

举例说明import

...    <groupId>maven</groupId>    <artifactId>B</artifactId>    <packageing>pom</packageing>    <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>    </dependencies>表示:将A中的依赖导入到B中
原创粉丝点击