资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

使用maven快速入门

Maven 基础知识

官网: 传送门

创新互联公司于2013年创立,先为朔州等服务建站,朔州等地企业,进行企业商务咨询服务。为朔州企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

Maven 项目结构

$ MavenProject
|-- pom.xml
|-- src
|   |-- main
|   |   `-- java
|   |   `-- resources
|   `-- test
|   |   `-- java
|   |   `-- resources
`-- README.md

POM文件

  • POM文件代表 工程对象模型(Project Object Model)它是使用Maven工作的基本组件,位于工程根目录。
  • POM文件支持继承


    4.0.0
    pom
    
        mscx-ad-discovery
        mscx-ad-zuul
        mscx-ad-gateway
        mscx-ad-discovery-nacos
        mscx-ad-common
        mscx-ad-db
        mscx-ad-sponsor
        mscx-ad-search
        mscx-ad-feign-sdk
    

    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.5.RELEASE
         
    

    com.sxzhongf
    mscx-ad
    1.0-SNAPSHOT
    分布式广告系统
    基于Spring Cloud Alibaba 实现的分布式广告系统

    
        1.8
        Greenwich.SR2
    

    
        
            org.projectlombok
            lombok
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        
    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

    
    
        
            spring-milestones
            Spring Milestones
            https://repo.spring.io/milestone
            
                false
            
        
        
            alibaba
            ali Milestones
            http://maven.aliyun.com/nexus/content/groups/public/
            
                false
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

Maven 坐标

使用maven快速入门

Maven Dependency

Maven思想 是 约定大于配置,默认依赖中,scope 是compile.

Scope类型
  • compile(会被打包到当前project)

    表示被依赖的package参与当前project的编译,包含后续的测试,运行周期都会参与,是一个强依赖。

  • test

    表示被依赖的jar 仅参与测试相关的处理,包裹测试代码的编译,执行。(如junit)

  • runtime

    表示被依赖的jar不需要参与项目的编译,但是后期的测试和运行周期需要参与。

  • provided

    打包的时候不需要包含进去,其他的Container会提供该依赖支持,理论上该依赖可以参与编译、测试运行等周期 ,相当于compile,但是在打包阶段做了exclude命令。

  • system

    从参与环境来看,和provided相同,但是被依赖项不会从maven仓库获取,而是从本地文件系统获取,一定需要配合systemPath属性使用

  • import

    This scope is only supported on a dependency of type pom in the <dependencyManagement> section.

依赖传递特性

官方解释:传送门

  • Dependency mediation (最近依赖原则)

    "nearest definition" means that the version used will be the closest one to your project in the tree of dependencies. For example, if dependencies for A, B, and C are defined as A -> B -> C -> D 2.0 and A -> E -> D 1.0, then D 1.0 will be used when building A because the path from A to D through E is shorter. You could explicitly add a dependency to D 2.0 in A to force the use of D 2.0.

    根据依赖深度,选择依赖路径最近的package version, 如果依赖深度相同,那么选择前一个。Note that if two dependency versions are at the same depth in the dependency tree, the first declaration wins.

  • Dependency management

    依赖管理(项目作者可直接指定依赖版本)

  • Dependency scope 如上一节所述

  • Excluded dependencies 排除依赖包中依赖项

  • Optional dependencies (相当于设置不允许将该依赖传递下去)

使用maven快速入门

常用命令

使用maven快速入门


网站名称:使用maven快速入门
网址分享:http://cdkjz.cn/article/gjdopj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220