使用IDEA创建第一个Maven项目的时候自动安装插件就是会一直提示 Cannot resolve plugin org.apache.maven.plugins:maven-clean-plugin:2.5 这个错误。搜了一下午的解决办法,主要原因大概是因为 IDEA 会自带库,所以使用的路径冲突了。但是这些解决办法都是基于需要重新下载库的基础上,修改镜面文件的。我不想额外下载,所以一直在找别的解决办法。
最后我在知乎上了解到导致这问题的原因可能不只是路径错误,还可能是因为访问外网的时候网络不给力。所以我试了下面的办法,成功解决问题。
- 在 C 盘用户目录下找到 ~/.m2/settings.xml文件,如果没有可以自己建一个(建一个记事本文件,后缀名改成.xml)
建立结果如上图
2.用记事本打开 .xml 文件,并复制一下代码进去,保存
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>central</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/central</url>
</mirror>
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>central repo</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>apache snapshots</mirrorOf>
<name>阿里云阿帕奇仓库</name>
<url>https://maven.aliyun.com/repository/apache-snapshots</url>
</mirror>
</mirrors>
<proxies/>
<activeProfiles/>
<profiles>
<profile>
<repositories>
<repository>
<id>aliyunmaven</id>
<name>aliyunmaven</name>
<url>https://maven.aliyun.com/repository/public</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>MavenCentral</id>
<url>http://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>aliyunmavenApache</id>
<url>https://maven.aliyun.com/repository/apache-snapshots</url>
</repository>
</repositories>
</profile>
</profiles>
</settings>
此办法是将库源下载从外网变成阿里云
3.最后重启IDEA 重新建立项目,成功!!
以上办法可以解决80%问题,如果还不成功可以使用一个100%成功率的办法:找一个有库的人,让他把库发你。
解决办法分享完毕,希望对你有用