一鸽疾、簡(jiǎn)介
Maven項(xiàng)目對(duì)象模型(POM)吊洼,可以通過(guò)一小段描述信息來(lái)管理項(xiàng)目的構(gòu)建,報(bào)告和文檔的項(xiàng)目管理工具軟件制肮。
Maven 除了以程序構(gòu)建能力為特色之外冒窍,還提供高級(jí)項(xiàng)目管理工具。由于 Maven 的缺省構(gòu)建規(guī)則有較高的可重用性豺鼻,所以常常用兩三行 Maven 構(gòu)建腳本就可以構(gòu)建簡(jiǎn)單的項(xiàng)目综液。由于 Maven 的面向項(xiàng)目的方法,許多 Apache Jakarta 項(xiàng)目發(fā)文時(shí)使用 Maven儒飒,而且公司項(xiàng)目采用 Maven 的比例在持續(xù)增長(zhǎng)意乓。
Maven這個(gè)單詞來(lái)自于意第緒語(yǔ)(猶太語(yǔ)),意為知識(shí)的積累,最初在Jakata Turbine項(xiàng)目中用來(lái)簡(jiǎn)化構(gòu)建過(guò)程届良。當(dāng)時(shí)有一些項(xiàng)目(有各自Ant build文件),僅有細(xì)微的差別圣猎,而JAR文件都由CVS來(lái)維護(hù)士葫。于是希望有一種標(biāo)準(zhǔn)化的方式構(gòu)建項(xiàng)目,一個(gè)清晰的方式定義項(xiàng)目的組成送悔,一個(gè)容易的方式發(fā)布項(xiàng)目的信息慢显,以及一種簡(jiǎn)單的方式在多個(gè)項(xiàng)目中共享JARs(摘自百度百科)
二、下載
下載地址:https://www.scala-sbt.org/download.html
三欠啤、安裝
????解壓縮
????tar zxvf?apache-maven-3.6.3-bin.tar.gz -C /mylab/soft
四荚藻、配置
???1.配置環(huán)境變量
? ? ? ? ? ? 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.增加國(guó)內(nèi)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加速中的地址应狱,不斷嘗試
五、驗(yàn)證
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
五祠丝、國(guó)內(nèi)倉(cāng)庫(kù)配置參考
網(wǎng)上收集了以下國(guó)內(nèi)maven倉(cāng)庫(kù)
<mirrors>
????????<mirror>
? ? ? ? ? ? <id>aliyun-maven</id>
? ? ? ? ? ? <name>阿里云公共倉(cāng)庫(kù)</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>阿里云谷歌倉(cāng)庫(kù)</name>
? ? ? ? ? ? <url>https://maven.aliyun.com/repository/google</url>
? ? ? ? ? ? <mirrorOf>central</mirrorOf>
? ? ? ? </mirror>
????????<mirror>
? ? ? ? ? ? <id>aliyun-apache-snapshots</id>
? ? ? ? ? ? <name>阿里云阿帕奇?zhèn)}庫(kù)</name>
? ? ? ? ? ? <url>https://maven.aliyun.com/repository/apache-snapshots</url>
? ? ? ? ? ? <mirrorOf>central</mirrorOf>
? ? ? ? </mirror>
????????<mirror>
? ? ? ? ? ? <id>aliyun-spring</id>
? ? ? ? ? ? <name>阿里云spring倉(cāng)庫(kù)</name>
? ? ? ? ? ? <url>https://maven.aliyun.com/repository/spring</url>
? ? ? ? ? ? <mirrorOf>central</mirrorOf>
? ? ? ? </mirror>
? ? ? ? <mirror>
? ? ? ? ? ? <id>aliyun-spring-plugin</id>
? ? ? ? ? ? <name>阿里云spring插件倉(cāng)庫(kù)</name>
? ? ? ? ? ? <url>https://maven.aliyun.com/repository/spring-plugin</url>
? ? ? ? ? ? <mirrorOf>central</mirrorOf>
? ? ? ? </mirror>
</mirrors>
六疾呻、參考
http://www.reibang.com/p/d95d0b1b6975?讓maven使用國(guó)內(nèi)鏡像和archetypeCatalog
1.關(guān)于settings.xml
mvn -X
會(huì)有如下提示
[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加入的以下內(nèi)容
<mirror>
? ? ? <id>alimaven</id>
? ? ? <name>aliyun maven</name>
? ? ? <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
? ? ? <mirrorOf>central</mirrorOf>? ? ? ?
</mirror>
里面有個(gè)<mirrorOf>central</mirrorOf>
代表的含義是
把我提供的這個(gè)阿里云的源當(dāng)作central源的代理吧,以后你需要訪問(wèn)那個(gè)名為central的源時(shí)写半,就把所有的請(qǐng)求轉(zhuǎn)發(fā)到我阿里云上岸蜗。
那么central又是什么呢?原來(lái)maven自己內(nèi)置了一個(gè)超級(jí)POM叠蝇,里面預(yù)先定義了名為central對(duì)應(yīng)的地址:
<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這個(gè)id對(duì)應(yīng)的是http://repo.maven.apache.org/maven2。
2.關(guān)于archetype-catalog.xml
從
http://repo.maven.apache.org/maven2/archetype-catalog.xml
下載
將archetype-catalog.xml保存到userhome/.m2文件夾
mvn時(shí)指定-DarchetypeCatalog=internal
即可使用maven默認(rèn)的archetype-catalog.xml悔捶,而不用再remote下載
通過(guò)以上設(shè)置铃慷,運(yùn)行以下命令就可以體驗(yàn)飛一樣的感覺(jué)
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用來(lái)指定maven-archetype-plugin讀取archetype-catalog.xml文件的位置:
internal:maven-archetype-plugin內(nèi)置的
local:mvn會(huì)使用本地的原型數(shù)據(jù)來(lái)供你選擇生成骨架原型
remote:指向maven中央倉(cāng)庫(kù)的Catalog
3.IDEA設(shè)置archetype-catalog.xml
打開(kāi)idea,點(diǎn)擊File——>settings——>Maven——>Runner——在Runner配置頁(yè)中的VM Options 中輸入
? ??????-DarchetypeCatalog=internal