Maven Summary

                Maven Summary

1. Introduction to maven

  maven is a project management tool. Maven is cross-platform, which means you can use the same commands on both Windows and Linux . Maven mainly serves the project construction, dependency management and project information management based on the Java platform.

2.maven main function

 (1) Dependency management

     2.1.1 Coordinates

     In order to automatically resolve any Java component, maven must uniquely identify them, which is the underlying basis of dependency management - coordinates. Maven 's coordinate elements include groupId , artifactId , version , packaging , classifier .

    2.1.2 Dependency scope

     Maven needs to use one set of classpaths when compiling project code, another set of classpaths when compiling and executing tests, and finally another set of classpaths when actually running . Dependency scope is used to control the relationship between dependencies and these three classpaths (compile classpath , test classpath , and run classpath ). Maven has the following dependency scopes: compile- compile dependency scope (default), test - test dependency scope (only tests are valid), provided -provided dependency scope (compile test valid, run invalid), runtime - runtime dependency scope ( The test is valid for running, invalid when compiling), system - system dependency scope (use with caution), import -import dependency scope (does not affect). Dependency scope and classpath relationship diagram:



 

   2.1.3 Transitive dependencies

Maven's transitive dependencies simplify and facilitate dependency declarations. Maven will resolve the pom of each direct dependency , and introduce those unnecessary indirect dependencies into the current project in the form of dependency transfer.

  2.1.4 Dependency Mediation

 When two different paths have the same two versions of X, it will cause duplication of dependencies, so one must be chosen. The first principle of relying on mediation is: the best road king takes precedence. The second principle is: the first declarant takes precedence.

  2.1.5 Optional dependencies

Ideally, optional dependencies should not be used, and there is no single responsibility principle.

  2.1.6 Exclude dependencies

  Used to exclude transitive dependencies.

  2.1.7 Collation dependencies

   Dependency collations are primarily used to address definitions that avoid duplication. Define a child element with a Maven property, which the Maven runtime will replace with the actual value.

2.1.8 Optimizing dependencies

  Optimize Maven, such as removing redundant dependencies, and explicitly declaring certain necessary dependencies.

2.1.9 Maven repository

For Maven, repositories are only divided into local repositories and remote repositories. Download Nexus to create your own private server.

 

(2) Project construction

2.1 Lifecycle

Base:

The Maven lifecycle is all about abstracting and unifying all build processes. The life cycle includes almost all build steps of a project, including cleanup, initialization, compilation, testing, packaging, integration testing, verification, deployment, and site generation. Maven 's life cycle is abstract, and the actual tasks are done by plugins.

Detailed explanation:

Maven has three independent life cycles , namely clean (the purpose is to clean the project), default (the purpose is to build the project), and site (the purpose is to build the project site). And each life cycle consists of phases, which are ordered, and the later phases depend on the earlier ones. The primary way to execute Maven tasks from the command line is to invoke Maven 's lifecycle phases.

2.2 Plugins

一个插件具有多个功能,每个功能就是一个插件目标。Maven的生命周期与插件相互绑定,用以完成实际的构建任务。具体而言,是生命周期的阶段与插件的目标相互绑定。

2.3 内置绑定

为了让用户几乎不用配置就能构建Maven项目,Maven在核心为一些主要的生命周期阶段绑定了很多插件目标。

2.4 自定义绑定

 除了内置绑定外,用户还能够自己选择将某个插件目标绑定到生命周期的某个阶段,这种绑定方式能让Maven项目在构建过程中执行更多更富特色的任务。

 

<!--[if !supportLists]-->(3)<!--[endif]-->项目信息管理

使用site插件可生成项目站点,能够帮助聚合项目信息,促进团队间的交流。

 

<!--[if !supportLists]-->3.<!--[endif]-->其他特性

<!--[if !supportLists]-->(1)<!--[endif]-->聚合与继承

Maven的聚合特性能够把项目的各个模块聚合在一起构建,而Maven的继承特性能帮助抽取各模块相同的依赖和插件等配置。前者主要是为了方便快速构建项目,后者主要是为了消除重复配置。

<!--[if !supportLists]-->(2)<!--[endif]-->构建web应用

The core idea of ​​Maven is "convention over configuration". Maven has its fixed directory structure.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326268942&siteId=291194637