本节主要讲了maven的依赖范围:

在pom.xml   dependency标签的scope中。eclipse中有编译的路径,maven中有编译,运行,测试的路径。

 

1  scope为test,为测试路径,多为junit jar包

2  scope为compile,为默认级别,编译测试运行都有效

3  scope为provided,编译和测试的时候有效

4  scope为runtime,运行和测试的时候有效  (如:jdbc驱动的实现)

5  scope为system,和compile一致,但是可移植能力差,引用的java_home(环境变量),更换电脑后将不能正常工作

6  scope为import,它只使用在dependencyManager中,表示从其他的pom中导入dependency的配置。

 

自己理解的:

maven编译需要jar包,运行需要jar包,测试也需要jar包。

 

scope为test:

            <dependency>
                <groupId>junit</groupId>            <!-- 此处是包名-->
                <artifactId>junit</artifactId>    <!-- 此处是项目名-->
                <version>4.1.0</version>            <!-- 此处是maven版本号-->
                <scope>test</scope>
            </dependency>

 

scope为import:

<dependency>
        <groupId>maven</groupId>
        <artifactId>A</artifactId>
        <version>1.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>

 

 

 

maven官网关于依赖机制的介绍:

http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

posted on 2018-11-02 22:38  菜鸟乙  阅读(309)  评论(0编辑  收藏  举报