一、maven的优势,下载,加载顺序
a) 约定优于配置
b) 简单
c) 测试支持
d) 构建简单
e) CI
f) 插件丰富
2. 下载
a) https://maven.apache.org/download.cgi
b) 安装
超级pom,pom的级联关系src/main/java是在这个地方规定的
c) maven-model-builder-3.3.9.jar/org/apache/maven/model
d) 配置 MVM_HOME
i. Windows path
ii. Linux .bash_profile
iii. MAVEN_OPTS
iv. 配置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>HumanReadable 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>
二、maven的传递依赖和作用域(转载)
https://blog.csdn.net/elricboa/article/details/70199727
三、maven仲裁管理:(转载)
https://blog.csdn.net/wanyanxgf/article/details/6617403
四、maven 生命周期 lifecycle/phase/goal
lifecycle,phase,goal以及mojo之间的作用和区别,可以参考下面这篇博客:
https://blog.csdn.net/glory1234work2115/article/details/51570073
1.A BuildLifecycle is Made Up of Phases
2.A BuildPhase is Made Up of Plugin Goals
五、 版本管理
a) 1.0-SNAPSHOT
i. repository 删除
ii. mvn cleanpackage -U (强制拉一次)
b) 主版本号.次版本号.增量版本号-<里程碑版本>
1.0.0-RELAESE
六、 常用命令
a) mvn clean compile
b) mvn clean 删除target/
c) mvn clean test test case junit/testNG
d) mvn clean package 打包
e) mvn clean install 把项目install到local repo
f) mvn deploy 发本地jar发布到remote
七、 插件
a) 常用插件
i. https://maven.apache.org/plugins/
ii. http://www.mojohaus.org/plugins.html
iii. findbugs 静态代码检查
https://blog.csdn.net/Fancy_xty/article/details/51718687(idea中安装findbug插件)
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <version>3.0.0</version> <configuration> <!-- <configLocation>${basedir}/springside-findbugs.xml</configLocation> --> <threshold>High</threshold> <effort>Default</effort> <findbugsXmlOutput>true</findbugsXmlOutput> <!-- findbugs xml输出路径--> <findbugsXmlOutputDirectory>target/site</findbugsXmlOutputDirectory> </configuration> </plugin>
iv. versions 统一升级版本号
1. mvnversions:set -DnewVersion=1.1
v. source 打包源代码(插件)
<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>
vi. assembly 打包zip、war
vii. tomcat7
八、 自定义插件 https://maven.apache.org/guides/plugin/guide-java-plugin-development.html
参考文档:https://blog.csdn.net/z69183787/article/details/52982249
-
dependency>
-
<groupId>org.apache.maven </groupId>
-
<artifactId>maven-plugin-api </artifactId>
-
<version>2.0 </version>
-
</dependency>
-
<dependency>
-
<groupId>org.apache.maven.plugin-tools </groupId>
-
<artifactId>maven-plugin-annotations </artifactId>
-
<version>3.2 </version>
-
<scope>provided </scope>
-
</dependency>
-
<dependency>
-
<groupId>org.codehaus.plexus </groupId>
-
<artifactId>plexus-utils </artifactId>
-
<version>3.0.8 </version>
-
</dependency>
a) <packaging>maven-plugin</packaging>
b) extendsAbstractMojo
c)
d) mvn install
e) 参数传递
九、 Profile
a) 使用场景dev/test/pro
<profiles> <profile> <id>dev</id> <properties> <profiles.activation>dev</profiles.activation> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>test</id> <properties> <profiles.activation>test</profiles.activation> </properties> </profile> <profile> <id>prd</id> <properties> <profiles.activation>prd</profiles.activation> </properties> </profile></profiles>
build> <finalName>winner-mvn-profile</finalName> <resources> <resource> <directory>src/main/resources/${profiles.activation}</directory> </resource> </resources></build>mvn install -Ptest 就是打包 test/* 即test目录下的所有文件
具体配置,参考这个博客:http://blog.51cto.com/xiaok007/1907509
b) setting.xml 家和公司两套
4. 仓库
maven构建私服:https://blog.csdn.net/shenshen123jun/article/details/9084293
a) 下载
b) 安装 解压
c) 使用http://books.sonatype.com/nexus-book/reference3/index.html
localhost:8081,账号admin/admin123
i. http://192.168.1.6:8081/nexus
ii. admin/admin123
d) 发布
i. pom.xml 配置
1.
2.
e) 下载jar配置
i. 配置mirror
ii. Profile
十、 archetype 模版化
可以参考博客:https://www.aliyun.com/jiaocheng/581611.html
a) 生成一个archetype
i. mvn archetype:create-from-project
ii. cd /target/generated-sources/archetype
iii. mvn install
b) 从archetype创建项目 mvnarchetype:generate -DarchetypeCatalog=local
查看系统变量:mvn help:system(idea终端窗口输入)
打包传参方式:mvn install -Dargs=123 args是一个参数名
maven统一给css,和js文件打上版本号,参考这个文档:
https://my.oschina.net/u/140938/blog/1553604