• Maven学习篇一:依赖了解


    1.依赖配置

    <project>
    ...
    <dependencies>
    <dependency>
    <groupId>xx</groupId>
    <artifactId>com.yy.xx</artifactId> 
    <version>..</version>
    <type>..</type>
    <scope>...</scope>
    <option></option>
    <exclusions>
    <exclusion>
    ....
    </exclusion>
    </exclusions>
    </dependency>
    </dependencies>
    
    </project>

    说明:
    groupId,artifactId,version :依赖的基本坐标
    type:依赖的类型,默认为jar
    scope:依赖的范围
    option: 标记依赖是否可选
    exclusions:排除传递性依赖

    2.依赖范围

    <dependencies>
    <dependency>
    <groupId>xx</groupId>
    <artifactId>com.test.xx</artifactId>
    <scope>test</scope>
    </dependency>
    </dependencies>

    1》comile:编译时依赖
    2》test:测试时依赖
    3》provided:已提供依赖范围,编译、测试生效,运行时不生效(例如servlet-api在tomcat中已经自带了,因此运行时不需要重复依赖)
    4》runtime:运行时依赖,仅对测试、运行生效,编译不生效。
    5》system:直接指定依赖的文件路径,和provided范围相同

    <dependencies>
    <dependency>
    <groupId>xx</groupId>
    <artifactId>com.test.xx</artifactId>
    <scope>system</scope>
    <systempath>${java.home}/lib/xx.jar</systempath>
    </dependency>
    </dependencies>


    6>import:导入依赖范围


    3.传达性依赖(间接依赖)

    A-->B-->C  A依赖B,B又依赖C,那么A会通过B将C也会依赖过去。

    传递依赖的范围取决于第一依赖的范围和第二依赖的范围(左边是第一依赖范围,上面是第二依赖范围,交叉部分为传递依赖范围)


    4.依赖调解

    1》A->B->E->C1.0,  A->D->C2.0   : 此时A会依赖C1还是C2 ?

    ---依赖原则1:路径最近者优先

    2》A->B->Y1.0, A->C->Y2.0   : 此时A会依赖Y1还是Y2  ?

    ---依赖原则2:第一声明优先

    5.可选依赖

    A->B, B->X(可选), B->Y(可选)

    如果3者依赖范围都是compile,则X,Y都是A的compile的依赖范围,但是由于X/Y都是可选依赖,所以X,Y不会被传递

    6.排除依赖

    exlusions可通过*排除所有依赖,也可以排除一个,或者多个。

    <dependencies>
    <!--排除所有传递依赖-->
    <dependency>
    <groupId>xx</groupId>
    <artifactId>com.yy.xx</artifactId> 
    <version>..</version>
    <exclusions>
    <exclusion>
        <groupId>*</groupId>
        <artifactId>*</artifactId> 
    </exclusion>
    </exclusions>
    </dependency>
    <!--排除一个或者 多个传递依赖-->
    <dependency>
    <groupId>xx</groupId>
    <artifactId>com.yy.xx</artifactId> 
    <version>..</version>
    <exclusions>
    <exclusion>
        <groupId>x1</groupId>
        <artifactId>com.xx.x1</artifactId> 
    </exclusion>
    <exclusion>
        <groupId>xn</groupId>
        <artifactId>com.xx.xn</artifactId> 
    </exclusion>
    </exclusions>
    </dependency>
    </dependencies>

    7.依赖优化

    mvn dependency:list   查看依赖列表

    mvn dependency:tree >a.txt   查看依赖树,生成a.txt

    mvn dependency:analyze

    依赖分析:展示结果有两部分

    1>Used undeclared dependencies : 表示项目中使用到了,但是没有显示声明的依赖

    2>Unused declared dependecies :  表示项目中未使用到,但是显示声明了的依赖,不能简单直接删除需要分析一下scope

    dependency:analyze只能分析编译、和测试范围的依赖。

  • 相关阅读:
    【转】前端防止 JS 调试技巧
    反爬虫 js怎样判断是真实点击事件还是模拟点击事件?
    js 前端 滑动验证
    【转】pyspider运行卡死在result_worker starting 的解决办法
    【转】pyspider all命令报错如下:ImportError: cannot import name 'DispatcherMiddleware' from 'werkzeug.wsgi'
    【转】pyspider中async关键字问题
    【转】Windows python3.7 下安装运行pyspider
    如何修改11g RAC集群名称
    Exadata健康检查工具EXAchk
    XD刷机中执行reclaimdisks.sh的作用
  • 原文地址:https://www.cnblogs.com/brant/p/5906914.html
Copyright © 2020-2023  润新知