基本命令
mvn clean compile #编译
mvn clean test #执行test
mvn clean package #打包
mvn clean install #下载到本地
解决:运行jar命令提示没有主清单属性
Manifest-Version: 1.0
Built-By: MaDon
Created-By: Apache Maven 3.6.1
Build-Jdk: 1.8.0_152
Main-Class: org.example.App #添加此行冒号后面需要有空格,底下必须有空行
依赖范围
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope> #scope指定了依赖范围
</dependency>
</dependencies>
如何调节依赖冲突
假设
项目A依赖于项目B,项目B依赖于项目C(v1), 项目A依赖于项目D,项目D依赖于项目E,项目E依赖于C(v2),
1、A--->B---->C(v1) ,
2、A------>D---->E----->C(v2)
分析:
依赖调解第一原则:路径优先,很明显,第一种路径深度是3,第二种路径深度是4,所以,maven会采用C(v1)
依赖调解第二原则:声明优先,假设路径深度相等,那么声明在前的会被引用。
那么这时候可以将其中一个依赖排除以免造成冲突
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.5.6</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
最后通过命令行确认依赖
dependency:list #列表
dependency:tree #树状
dependency:analyze #分析
修改maven配置
修改本地存储位置:在setting.xml文件中(一般在解压后的maven包内)
<localRepository>D:/apache-maven-3.6.1/repository</localRepository>
修改远端仓库的位置
<mirrors>
<mirror>
//该镜像的id
<id>nexus-aliyun</id>
//该镜像用来取代的远程仓库,central是中央仓库的id
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
//该镜像的仓库地址,这里是用的阿里的仓库
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
架设私服
一般使用Sonatype和jfrog
docker搭建maven私服_q495673918的博客-CSDN博客_docker安装maven私服
<repositories>
<repository>
<id>maven-releases</id>
<name>Nexus Release Repository</name>
<url>http://192.168.121.131:8081/repository/maven-releases/</url>
<releases>true</releases> #下载发布版
<snapshots>false</snapshots> #不下载测试版
</repository>
</repositories>
生命周期
- clean:项目清理的处理
- default(或 build):项目部署的处理
- site:项目站点文档创建的处理