Maven dependencies & dependencyM

2019-09-16  本文已影响0人  PC_Repair

一般在项目顶层的 Pom 文件中,我们会看到 dependencyManagement 元素,通过它来管理 jar 包的版本,让子项目中引用一个依赖而不用显示的列车版本号。

Maven 会沿着父子层次向上走,直到找到一个拥有 dependencyManagement 元素的项目,然后它就会使用这个 dependencyManagement 元素中指定的版本号。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
    </parent>

    <groupId>com.jiaflu.soa</groupId>
    <artifactId>soa-springboot-parent</artifactId>

    <packaging>pom</packaging>

    <properties>
        <spring.swagger>2.9.2</spring.swagger>
        <springboot.graphql.version>5.0.2</springboot.graphql.version>
        <graphql.java.tools.version>5.2.4</graphql.java.tools.version>
    </properties>

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

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.graphql-java</groupId>
                <artifactId>graphiql-spring-boot-starter</artifactId>
                <version>${springboot.graphql.version}</version>
            </dependency>

            <dependency>
                <groupId>com.graphql-java</groupId>
                <artifactId>graphql-spring-boot-starter</artifactId>
                <version>${springboot.graphql.version}</version>
            </dependency>

            <dependency>
                <groupId>com.graphql-java</groupId>
                <artifactId>graphql-java-tools</artifactId>
                <version>${graphql.java.tools.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.jiaflu.soa</groupId>
        <artifactId>soa-springboot-parent</artifactId>
        <version>2.1.3.RELEASE</version>
    </parent>

    <groupId>com.jiaflu.soa.soagraphql</groupId>
    <artifactId>soa-graphql</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.graphql-java</groupId>
            <artifactId>graphql-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.graphql-java</groupId>
            <artifactId>graphiql-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.graphql-java</groupId>
            <artifactId>graphql-java-tools</artifactId>
        </dependency>
    </dependencies>

</project>

这样做的好处:

区别:

上一篇下一篇

猜你喜欢

热点阅读