一、简介
Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的项目管理工具软件。
Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具。由于 Maven 的缺省构建规则有较高的可重用性,所以常常用两三行 Maven 构建脚本就可以构建简单的项目。由于 Maven 的面向项目的方法,许多 Apache Jakarta 项目发文时使用 Maven,而且公司项目采用 Maven 的比例在持续增长。
Maven这个单词来自于意第绪语(犹太语),意为知识的积累,最初在Jakata Turbine项目中用来简化构建过程。当时有一些项目(有各自Ant build文件),仅有细微的差别,而JAR文件都由CVS来维护。于是希望有一种标准化的方式构建项目,一个清晰的方式定义项目的组成,一个容易的方式发布项目的信息,以及一种简单的方式在多个项目中共享JARs(摘自百度百科)
二、下载
下载地址:https://www.scala-sbt.org/download.html
三、安装
解压缩
tar zxvf apache-maven-3.6.3-bin.tar.gz -C /mylab/soft
四、配置
1.配置环境变量
vi ~/.bashrc
#apache-maven-3.6.3
export MAVEN_HOME=$MYLAB_BASE_HOME/apache-maven-3.6.3
export PATH=$MAVEN_HOME/bin:$PATH
2.增加国内maven源
加速器,修改$MAVEN_HOME/conf文件夹下的settings.xml文件,添加如下镜像配置:
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
注:参考sbt加速中的地址,不断尝试
五、验证
mvn -h
usage: mvn [options] [<goal(s)>] [<phase(s)>]
Options:
-am,--also-make If project list is specified, also
build projects required by the
list
-amd,--also-make-dependents If project list is specified, also
build projects that depend on
projects on the list
-B,--batch-mode Run in non-interactive (batch)
mode (disables output color)
-b,--builder <arg> The id of the build strategy to
use
-C,--strict-checksums Fail the build if checksums don't
match
-c,--lax-checksums Warn if checksums don't match
-cpu,--check-plugin-updates Ineffective, only kept for
backward compatibility
-D,--define <arg> Define a system property
-e,--errors Produce execution error messages
-emp,--encrypt-master-password <arg> Encrypt master security password
-ep,--encrypt-password <arg> Encrypt server password
-f,--file <arg> Force the use of an alternate POM
file (or directory with pom.xml)
-fae,--fail-at-end Only fail the build afterwards;
allow all non-impacted builds to
continue
-ff,--fail-fast Stop at first failure in
reactorized builds
-fn,--fail-never NEVER fail the build, regardless
of project result
-gs,--global-settings <arg> Alternate path for the global
settings file
-gt,--global-toolchains <arg> Alternate path for the global
toolchains file
-h,--help Display help information
-l,--log-file <arg> Log file where all build output
will go (disables output color)
-llr,--legacy-local-repository Use Maven 2 Legacy Local
Repository behaviour, ie no use of
_remote.repositories. Can also be
activated by using
-Dmaven.legacyLocalRepo=true
-N,--non-recursive Do not recurse into sub-projects
-npr,--no-plugin-registry Ineffective, only kept for
backward compatibility
-npu,--no-plugin-updates Ineffective, only kept for
backward compatibility
-nsu,--no-snapshot-updates Suppress SNAPSHOT updates
-ntp,--no-transfer-progress Do not display transfer progress
when downloading or uploading
-o,--offline Work offline
-P,--activate-profiles <arg> Comma-delimited list of profiles
to activate
-pl,--projects <arg> Comma-delimited list of specified
reactor projects to build instead
of all projects. A project can be
specified by [groupId]:artifactId
or by its relative path
-q,--quiet Quiet output - only show errors
-rf,--resume-from <arg> Resume reactor from specified
project
-s,--settings <arg> Alternate path for the user
settings file
-t,--toolchains <arg> Alternate path for the user
toolchains file
-T,--threads <arg> Thread count, for instance 2.0C
where C is core multiplied
-U,--update-snapshots Forces a check for missing
releases and updated snapshots on
remote repositories
-up,--update-plugins Ineffective, only kept for
backward compatibility
-v,--version Display version information
-V,--show-version Display version information
WITHOUT stopping build
-X,--debug Produce execution debug output
五、国内仓库配置参考
网上收集了以下国内maven仓库
<mirrors>
<mirror>
<id>aliyun-maven</id>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
<mirrorOf>public</mirrorOf>
</mirror>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>CN</id>
<name>OSChina Central</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>aliyun-google</id>
<name>阿里云谷歌仓库</name>
<url>https://maven.aliyun.com/repository/google</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>aliyun-apache-snapshots</id>
<name>阿里云阿帕奇仓库</name>
<url>https://maven.aliyun.com/repository/apache-snapshots</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>aliyun-spring</id>
<name>阿里云spring仓库</name>
<url>https://maven.aliyun.com/repository/spring</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>aliyun-spring-plugin</id>
<name>阿里云spring插件仓库</name>
<url>https://maven.aliyun.com/repository/spring-plugin</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
六、参考
https://www.jianshu.com/p/d95d0b1b6975 让maven使用国内镜像和archetypeCatalog
1.关于settings.xml
mvn -X
会有如下提示
[DEBUG] Reading global settings from /mylab/soft/apache-maven-3.6.3/conf/settings.xml
[DEBUG] Reading user settings from /home/hadoop/.m2/settings.xml
[DEBUG] Reading global toolchains from /mylab/soft/apache-maven-3.6.3/conf/toolchains.xml
[DEBUG] Reading user toolchains from /home/hadoop/.m2/toolchains.xml
[DEBUG] Using local repository at /home/hadoop/.m2/repository
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for /home/hadoop/.m2/repository
setting2.xml加入的以下内容
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
里面有个<mirrorOf>central</mirrorOf>
代表的含义是
把我提供的这个阿里云的源当作central源的代理吧,以后你需要访问那个名为central的源时,就把所有的请求转发到我阿里云上。
那么central又是什么呢?原来maven自己内置了一个超级POM,里面预先定义了名为central对应的地址:
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
可以看到,central这个id对应的是http://repo.maven.apache.org/maven2。
2.关于archetype-catalog.xml
从
http://repo.maven.apache.org/maven2/archetype-catalog.xml
下载
将archetype-catalog.xml保存到userhome/.m2文件夹
mvn时指定-DarchetypeCatalog=internal
即可使用maven默认的archetype-catalog.xml,而不用再remote下载
通过以上设置,运行以下命令就可以体验飞一样的感觉
mvn archetype:generate\
-DgroupId=Group1\
-DartifactId=Flink-QuickStart-Scala\
-DarchetypeGroupId=org.apache.flink\
-DarchetypeArtifactId=flink-quickstart-scala\
-DinteractiveMode=false\
-DarchetypeVersion=1.11.1\
-DarchetypeCatalog=internal
其中archetypeCatalog用来指定maven-archetype-plugin读取archetype-catalog.xml文件的位置:
internal:maven-archetype-plugin内置的
local:mvn会使用本地的原型数据来供你选择生成骨架原型
remote:指向maven中央仓库的Catalog
3.IDEA设置archetype-catalog.xml
打开idea,点击File——>settings——>Maven——>Runner——在Runner配置页中的VM Options 中输入
-DarchetypeCatalog=internal