mvn -Dmaven.test.skip=true -U clean install
html
mvn clean package -U
(強制拉一次)java
mvn archetype:create-from-project
linux
mvn archetype:generate -DarchetypeCatalog=local
spring
mvn dependency:tree
apache
mvn clean package -Dmaven.test.skip=true -Ptest
json
https://maven.apache.org/down...api
maven-model-builder-3.6.0.jar/org/apache/maven/modeltomcat
本身的classloaderbash
全部本身的倉庫配置maven
超級父pom
Linux .bash_profile
export M2_HOME=/Users/xx/tools/apache/apache-maven-3.6.0
配置setting.xml
<mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>ui</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://uk.maven.org/maven2/</url> </mirror> <mirror> <id>osc</id> <mirrorOf>central</mirrorOf> <url>http://maven.oschina.net/content/groups/public/</url> </mirror> <mirror> <id>osc_thirdparty</id> <mirrorOf>thirdparty</mirrorOf> <url>http://maven.oschina.net/content/repositories/thirdparty/</url> </mirror>
通常是域名反寫
com.zzjson
功能命名
版本號
打包方式 默認是jar
只能出如今父pom
統一版本號
聲明 (子POM裏用到再引)
Type 默認jar
默認
編譯(maven編譯整個項目)
例如spring-core
測試
編譯 例如 servlet,tomcat已經有了
打包不會打進去,至關於compile可是在打包階段作了exclude操做
運行時 例如JDBC驅動實現
本地一些jar 例如短信jar
compile:編譯依賴範圍,在編譯,測試,運行時都須要。
test: 測試依賴範圍,測試時須要。編譯和運行不須要。如Junit
runtime: 運行時依賴範圍,測試和運行時須要。編譯不須要。如JDBC驅動包
provided:已提供依賴範圍,編譯和測試時須要。運行時不須要。如servlet-api
system:系統依賴範圍。本地依賴,不在maven中央倉庫。
第一列表示直接依賴的scope,第一行表示間接依賴的scope
compile | test | provided | runtime | |
---|---|---|---|---|
compile | compile | - | - | runtime |
test | test | - | - | test |
provided | provided | - | provided | provided |
runtime | runtime | - | - | runtime |
mvn dependency:tree
若是都定義了版本,那麼以最近的爲準
最短路徑原則
加載前後原則
排除包
clean 清理項目
pre-clean
執行一些清理前須要完成的工做clean
清理上一次構建生成的文件post-clean
執行一些清理後須要完成的工做 lifecycle/phase/goal
1.A Build Lifecycle is Made Up of Phases
一個生命週期由多個phase組成的
2.A Build Phase is Made Up of Plugin Goals
一個phases是由多個goals組成的
生命週期運行會從前日後
1.0-SNAPSHOT
i. repository 刪除
ii. mvn clean package -U
(強制拉一次)
主版本號.次版本號.增量版本號-<里程碑版本>
1.0.0-RELAESE
<plugins> <plugin> <artifactId>plugin</artifactId> <groupId>com.zzjson</groupId> <version>1.1</version> <configuration> <msg> ddd </msg> <list> <list> d </list> <list> d1 </list> </list> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>myplugin</goal> </goals> </execution> </executions> </plugin> </plugins>
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>versions-maven-plugin</artifactId> <version>2.3</version> </plugin>
http://www.mojohaus.org/versions-maven-plugin/index.html
mvn versions:set -DnewVersion=1.1-SNAPSHOT
<plugin> <artifactId>maven-source-plugin</artifactId> <version>2.3</version> <executions> <execution> <id>attach-sources</id> <phase>install</phase> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin>
<plugin> <artifactId>maven-assembly-plugin</artifactId> <version>3.1.0</version> <configuration> <archive> <manifest> <mainClass>shuncom.dubbo.task.main.BootStrap</mainClass> </manifest> </archive> <descriptorRefs>jar-with-dependencies</descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <port>8080</port> <path>/</path> </configuration> </plugin>
<packaging>maven-plugin</packaging>
導入依賴
<dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> <version>3.5.0</version> </dependency> <dependency> <groupId>org.apache.maven.plugin-tools</groupId> <artifactId>maven-plugin-annotations</artifactId> <version>3.5</version> </dependency>
extends AbstractMojo
mvn install
參數傳遞
Profile
使用場景 dev/test/pro
setting.xml 家和公司兩套
http://books.sonatype.com/nex...
http://lohost:8081/nexus(自帶jetty)
admin/admin123
Type:
依賴jar包的方式
把group做爲合集提供,挨個jar去倉庫查找
本地的
三方的
阿里短信jar包
released
snapshosts
當maven dependce本地倉庫沒有找到,私服也沒有,則去下載,從遠端下載到私服
在pom.xml配置
<distributionManagement> <repository> <id>repo-mirrors</id> <name>center-repository</name> <url>http://uk.maven.org/maven2</url> </repository> <snapshotRepository> <id>repo-mirrors</id> <name>center-repository</name> <url>http://uk.maven.org/maven2</url> </snapshotRepository> </distributionManagement>
mvn deploy
也須要驗證用戶名密碼,id須要和pom中一致
mvn archetype:create-from-project
cd /target/generated-sources/archetype
mvn install
b) 從archetype建立項目
mvn archetype:generate -DarchetypeCatalog=local
配置文件
<profiles> <profile> <id>dev</id> <properties> <profiles.active>dev</profiles.active> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> <profile> <id>prod</id> <properties> <profiles.active>prod</profiles.active> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>test</id> <properties> <profiles.active>test</profiles.active> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> </profiles>
<resources> <resource> <directory>${basedir}/src/main/resources</directory> <excludes> <exclude>conf/**</exclude> </excludes> </resource> <resource> <directory>src/main/resources/conf/${profiles.active}</directory> </resource> </resources>
代碼,指定不一樣的環境
<profile> <id>ali</id> <repositories> <repository> <id>nexus</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> <checksumPolicy>warn</checksumPolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> <checksumPolicy>fail</checksumPolicy> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> <checksumPolicy>warn</checksumPolicy> </releases> <snapshots> <enabled>true</enabled> <checksumPolicy>fail</checksumPolicy> <updatePolicy>always</updatePolicy> </snapshots> </pluginRepository> </pluginRepositories> </profile> <profile> <id>external</id> <repositories> <repository> <id>repo-mirrors</id> <url>http://uk.maven.org/maven2</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>plugin-repo-mirror</id> <url>http://uk.maven.org/maven2</url> </pluginRepository> </pluginRepositories> </profile>
mvn clean package -Dmaven.test.skip=true -Ptest
[root@snails ~]# wget http://download.sonatype.com/nexus/3/latest-unix.tar.gz
dependencyManagement使用可以幫助咱們進行子項目的版本號管理
<dependencyManagement> <dependencies> <dependency> <groupId>com.zzjson.dubbo.order</groupId> <artifactId>order-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </dependencyManagement>
版本會替換倉庫中的jar
版本不會替換