Apache Maven 是什么
Manve 是软件项目管理和编译的工具, 基于POM(Project Object Model)使项目的构建(build),分发(distribute) 更容易. 一个POM是一个XML文档, 类似于Java中的Object, 所有POM也都是一个Super POM的子脚本
下载/安装 Maven
下载
https://maven.apache.org/download.cgi
- 注意要求的Java 版本.
安装
前置条件 - 配置了对应的Java版本(JAVA_HOME 和PATH)
安装步骤 -
1. 下载后先解压到任意目录
unzip apache-maven-3.9.6-bin.zip
tar xzvf apache-maven-3.9.6-bin.tar.gz
2. 设置环境变量
添加apache-maven-x.x.x/bin目录到PATH 中. 如果不知道如何设置可以查询一下这里就不赘述了.
3. 测试结果
mvn -v
Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: /opt/apache-maven-3.9.6
Java version: 1.8.0_45, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.8.5", arch: "x86_64", family: "mac"
运行
mvn [options] [<goal(s)>] [<phase(s)>]
The built-in lifecycles and their most used phases, in order, are:
-
clean -
clean
-
default -
validate
,compile
,test
,package
,verify
,install
,deploy
-
site -
site
,site-deploy
常用的Options的作用, 每个Option都是一个Plugin:
Core Plugins | 描述 |
clean | Clean up after the build. |
compiler | Compiles Java sources. |
install | Install the built artifact into the local repository. |
- Build plugins will be executed during the build and they should be configured in the
<build/>
element from the POM. - Reporting plugins will be executed during the site generation and they should be configured in the
<reporting/>
element from the POM.
配置
Maven – Configuring Apache Maven
- 修改.m2的位置
- 设置代理
- JVM参数等
Project Object Manage(POM )
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- The Basics -->
<groupId>项目所属group id, 一般为公司域名倒写. 例如 org.apache.maven </groupId>
<artifactId>一个具体的项目</artifactId>
<version>项目版本</version>
<packaging>...</packaging>
<dependencies>...</dependencies>
<parent>父工程的 artifactId</parent>
<dependencyManagement>...</dependencyManagement>
<modules>...</modules>
<properties>...</properties>
<!-- Build Settings -->
<build>...</build>
<reporting>...</reporting>
<!-- More Project Information -->
<name>...</name>
<description>...</description>
<url>...</url>
<inceptionYear>...</inceptionYear>
<licenses>...</licenses>
<organization>...</organization>
<developers>...</developers>
<contributors>...</contributors>
<!-- Environment Settings -->
<issueManagement>...</issueManagement>
<ciManagement>...</ciManagement>
<mailingLists>...</mailingLists>
<scm>...</scm>
<prerequisites>...</prerequisites>
<repositories>...</repositories>
<pluginRepositories>...</pluginRepositories>
<distributionManagement>...</distributionManagement>
<profiles>...</profiles>
</project>
参考文档
Maven – Welcome to Apache Maven
https://mvnrepository.com/
未完待续....