13.继承

test范围的依赖不能传递,因此需要统一管理各工程中test范围依赖的版本

[1]创建父工程(打包方式为pom)

<groupId>com.company.test</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

[2]在子工程中引用父工程

<parent>
    <groupId>com.company.test</groupId>
    <artifactId>Parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <!--填写以当前工程目录为基准的父工程的pom.xml文件的相对路径-->
    <relativePath>../xx/pom.xml</relativePath>
</parent>

[3]将子工程中与父工程坐标中相同的内容删除,如删除子工程中的(也可以不删除)

<groupId>com.company.test</groupId>

[4]在父工程统一管理

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

[5]记得在子工程中把版本号<version>4.0</version>删去,否则父工程的版本会被子工程覆盖

猜你喜欢

转载自blog.csdn.net/yztfst/article/details/82504167