目录
1.报错提示Could not transfer artifact
1.下载
wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
2.安装
yum install apache-maven -y
3.检查是否安装成功
mvn -v
4.问题
1.报错提示Could not transfer artifact
原因是部署maven的机器是通过代理上网的,所有maven需要设置代理
mvn -v
vim settings.xml
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>root</username>
<password>password</password>
<host>ip</host>
<port>3128</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
2.报错冲突
Transaction check error:
file /usr/share/java/plexus/plexus-cipher.jar from install of apache-maven-0:3.5.2-1.el7.noarch conflicts with file from package plexus-cipher-1.7-5.el7.noarch
file /usr/share/java/plexus/plexus-sec-dispatcher.jar from install of apache-maven-0:3.5.2-1.el7.noarch conflicts with file from package plexus-sec-dispatcher-1.4-13.el7.noarch
file /usr/share/java/maven-wagon/file.jar from install of apache-maven-0:3.5.2-1.el7.noarch conflicts with file from package maven-wagon-0:2.4-3.el7.noarch
file /usr/share/java/maven-wagon/provider-api.jar from install of apache-maven-0:3.5.2-1.el7.noarch conflicts with file from package maven-wagon-0:2.4-3.el7.noarch
Error Summary
解决:
依次删除冲突的包,如果提示有依赖导致删除不了,则先删除依赖的包
rpm -e plexus-cipher-1.7-5.el7.noarch
rpm -e aether-connector-wagon-1.13.1-13.el7.noarch
rpm -e maven-wagon-0:2.4-3.el7.noarch
3.下载文件速度慢
mvn -v
vim settings.xml
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
5.仓库配置
1.私服配置
查找安装位置
whereis maven
修改配置settings.xml
#设置本地仓库地址
<localRepository>/usr/local/repo</localRepository>
#设置私服访问帐号密码
<server>
<id>maven-public</id>
<username>admin</username>
<password>admin</password>
</server>
#仓库地址
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<name>nexus</name>
<url>http://ip:port/nexus/repository/maven-public/</url>
<release>
<enabled>true</enabled>
</release>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>nexus</name>
<url>http://ip:port/nexus/repository/public/</url>
<release>
<enabled>true</enabled>
</release>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
#激活配置
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
2.非私服仓库配置
当maven依赖的jar包不在本地仓库时,会先从mirror里面去找,找不到再去repo里面去找,mirror相当于拦截请求,改变仓库请求地址。
<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>