Maven的安装(Ubuntu22.04)
安装maven必须安装java_jdk
apt install openjdk-8-jdk
下载对应版本maven,解压
wget https://mirrors.cnnic.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz --no-check-certificate
tar -zxvf apache-maven-3.5.4-bin.tar.gz
在/usr/local/目录下新建maven文件并将解压文件移动到maven
mkdir /usr/local/maven
mv apache-maven-3.5.4 /usr/local/maven
ln -s /usr/local/maven/bin/mvn /usr/bin/mvn
# 与jenkins联合使用时,jenkins会到/usr/bin/下找mvn命令,如果没有会报错
配置maven环境变量
vim /etc/profile
export MAVEN_HOME=/usr/local/maven/apache-maven-3.5.4
export PATH=${PATH}:${MAVEN_HOME}/bin
source /etc/profile
输入mvn测试是否成功
可使用mvn package
命令打包项目
至此maven安装完成
使用maven打包SpringBoot的jar包易发生问题及解决方案
maven换源
进入maven目录
cd /usr/local/maven/apache-maven-3.5.4/conf/
找到settings.xml
在mirrors标签下加入阿里云镜像源
<mirrors>
<!-- 阿里云仓库 -->
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<!-- 中央仓库1 -->
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<!-- 中央仓库2 -->
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
</mirrors>
wq保存即可换源,mvn打包时download飞快
Maven打包SpringBoot项目时出现Test异常
打包失败异常如下
1、直接修改 maven 配置命令:
// 不会编译测试
mvn install -Dmaven.test.skip=true
或
// 忽略测试执行期间发生的任何故障
mvn install -Dmaven.test.failure.ignore=true
2、在项目的 pom.xml 文件中加入如下配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<skipTests>true</skipTests> <!-- 不会编译测试 -->
</configuration>
</plugin>
或
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore> <!-- 忽略测试执行期间发生的任何故障 -->
</configuration>
</plugin>
注:将代码插入plugins
标签下,保存即可
存在Test错误,但能正常打包
参考文章
https://blog.csdn.net/qq_26095375/article/details/120859485
https://blog.csdn.net/xhaimail/article/details/107532583
https://www.cnblogs.com/chinaifae/p/10212437.html
https://blog.csdn.net/weixin_43793525/article/details/124074574