maven#dependencyManagement

dependencyManagement 用于对版本进行管理,不下载实际的jar包。

如果一个包在dependencyManagement中进行声明了,那么在pom中的<dependencies><dependency>节点下就不用些版本号了。

  <!--这里才会真正的下载jar包,对应的jar的版本会去dependencyManagement中去寻找,找不到就报错了,否则就要在下面写出version-->   
 <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <!--依赖版本定义,这里只是声明,如果要用到jar,就用我这边规定的版本-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>0.2.1.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

猜你喜欢

转载自www.cnblogs.com/luohaonan/p/12385943.html