• maven介绍


    项目管理构建工具

    Maven Ant Gradle

    1.Maven的概念

    Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建、报告和文档的软件项目管理工具。

    2.如何window下搭建Maven环境

    2.1在http://maven.apache.org下载maven

    2.2安装maven后配置环境变量

    如:在系统变量path中添加:D:eclipseapache-maven-3.5.3in

    项目管理构建工具

    Maven Ant Gradle

    1.Maven的概念

    Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建、报告和文档的软件项目管理工具。

    2.如何window下搭建Maven环境

    2.1在http://maven.apache.org下载maven

    2.2安装maven后配置环境变量

    如:在系统变量path中添加:D:eclipseapache-maven-3.5.3in

     

    3.Maven的目录结构

     

    4.pom.xml结构

     

    5.Maven的常用命令

     

     

    6.自动创建maven约定的目录骨架

    使用archetype插件

     

     

     

    7.maven仓库

    Maven仓库分为本地仓库与远程仓库,一般在本地仓库中查找有无依赖,没有则到远程仓库查找下载,再没有则会报错

    默认的中央仓库的地址:

    https://repo.maven.apache.org/maven2

    http://search.maven.org/

    8.镜像仓库

    9.maven的生命周期

    执行某个阶段时其前面的阶段会被依次的顺序执行

     

     

    10.pom常用标签备注

    <!--指定当前pom的版本 -->
    
    <modelVersion>4.0.0</modelVersion>
    
    <!--反写的公司网址+項目名 -->
    
    <groupId>com.zgk</groupId>
    
    <!--项目名+模块名 -->
    
    <artifactId>maven.test</artifactId>
    
    <!--第一个0表示大版本号第二个0分支版本号 第三个0表示小版本号 snapshot快照版本(不稳定,尚处于开发中的版本) alpha内测版本 beta公测版本 release稳定版本 GA正式发布版本-->
    
    <version>0.0.1-SNAPSHOT</version>
    
    <!--默认是jar 还可以是war zip pom-->
    
    <packaging>jar</packaging>
    
    <!--项目名 -->
    
    <name>hi</name>
    
    <!--项目地址 -->
    
    <url>http://maven.apache.org</url>
    
    <!--项目描述 -->
    
    <description></description>
    
    <!--开发人员列 -->
    
    <developers></developers>
    
    <!--许可证信息 -->
    
    <licenses></licenses>
    
    <!--组织者信息-->
    
    <organization></organization>
    
    <!--依赖列表 -->
    
    <dependencies>
    
      <dependency>
    
        <!--坐标groupId -->
    
        <groupId></groupId>
    
        <!--坐标artifactId  -->
    
        <artifactId></artifactId>
    
        <!--版本  -->
    
        <version></version>
    
        <!--类型  -->
    
        <type></type>
    
        <!--依赖的范围 如test表示测试范围内有效 -->
    
          <scope>test</scope>
    
          <!--设置依赖是否可选 true false-->
    
          <optional></optional>
    
          <!--排除依赖传递列表 -->
    
          <exclusions>
    
             <exclusion></exclusion>
    
          </exclusions>
    
      </dependency>
    
      </dependencies>
    
      <!-- 依赖管理,一般定义在父模块供子模块继承使用 -->
    
      <dependencyManagement>
    
         <dependencies>
    
             <dependency></dependency>
    
          </dependencies>
    
      </dependencyManagement>
    
     
    
      <!--构建行为  -->
    
      <build>
    
      <!--插件列表  -->
    
      <plugins>
    
        <plugin>
    
           <groupId></groupId>
    
           <artifactId></artifactId>
    
           <version></version>
    
        </plugin>
    
      </plugins>
    
      </build>
    
      <!-- 子模块在父模块中继承 -->
    
      <parent></parent>
    
      <!-- 聚合多个maven项 -->
    
      <modules>
    
         <module></module>
    
      </modules>

    11.依赖的范围

    Dependency scope is used to limit the transitivity of a dependency, and also to affect the classpath used for various build tasks.

    There are 6 scopes available:

    • Compile 默认范围,编译测试运行都有效
      This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.
    • Provided 在测试和编译的时候有效,运行的时候不会被加入
      This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
    • Runtime 在测试和运行时有效
      This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.
    • Test 只在测试范围有效
      This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases. This scope is not transitive.
    • System 与系统本机相关,可移植性差,如本机的Javahome,只能在本机有效
      This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.
    • import (only available in Maven 2.0.9 or later)
    • 导入的范围,它只使用在dependencyManagement中,表示从其他的pom中导入dependecy的配置
      This scope is only supported on a dependency of type pom in the <dependencyManagement> section. It indicates the dependency to be replaced with the effective list of dependencies in the specified POM's <dependencyManagement> section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.

    Each of the scopes (except for import) affects transitive dependencies in different ways, as is demonstrated in the table below. If a dependency is set to the scope in the left column, transitive dependencies of that dependency with the scope across the top row will result in a dependency in the main project with the scope listed at the intersection. If no scope is listed, it means the dependency will be omitted.

     

    compile

    provided

    runtime

    test

    compile

    compile(*)

    -

    runtime

    -

    provided

    provided

    -

    provided

    -

    runtime

    runtime

    -

    runtime

    -

    test

    test

    -

    test

    -

    12.依赖传递

     

     

    13.依赖冲突

    基本依据两条原则

    1. 短路优先(谁的路径短,用哪个)

     

    2.先声明先优先(路径相同,谁先声明,先解析谁)

     

    14.聚合继承

    1.聚合

     

    2.继承

  • 相关阅读:
    HDU 5919 分块做法
    HDU 3333 分块求区间不同数和
    CF 333E 计算几何+bitset优化
    hdu 1043 八数码--打表
    hdu 1043 八数码问题-A*搜索
    hdu 5919 主席树
    hiho1388 FFT/NTT
    HDU 5869区间CGD不同种类数---树状数组+map统计区间不同种类数(离线)
    HDU 5875 二分+st表
    HDU 5898 基础数位DP
  • 原文地址:https://www.cnblogs.com/kk-home/p/9195615.html
Copyright © 2020-2023  润新知