您的位置:首页 > 其它

idea maven找不到依赖

一同胡 2020-10-17 10:02 25 查看 https://blog.51cto.com/fan0128
相信大家开发中总是遇到maven爆红的情况,其中的原因可能有maven仓库源加载缓慢,可以在项目中配置自己的私服或者配置国内的景象源,常用镜像源maven的settings文件配置
```
<mirrors>
<mirror>
<id>aliyun-central</id>
<mirrorOf>central</mirrorOf>
<name>aliyun-central</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<mirror>
<id>nexus-osc</id>
<mirrorOf>osc-central</mirrorOf>
<name>Nexus osc</name>
<url>http://maven.oschina.net/content/groups/public/</url>
</mirror>
<mirror>
<id>nexus-mvn</id>
<mirrorOf>mvn-central</mirrorOf>
<name>Nexus mvn</name>
<url>http://mvnrepository.com</url>
</mirror>
<mirror>
<id>nexus-spring</id>
<mirrorOf>spring-central</mirrorOf>
<name>Nexus spring</name>
<url>https://repo.spring.io/libs-milestone</url>
</mirror>

</mirrors>

<profiles>
<profile>
<id>ali</id>
<activation>
<jdk>1.8</jdk>
</activation>

<repositories>
<repository>
<id>ali</id>
<name>Repository for JDK 1.8 builds</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
<layout>default</layout>
</repository>
</repositories>
</profile>
<profile>
<id>mvn</id>
<activation>
<jdk>1.8</jdk>
</activation>

<repositories>
<repository>
<id>mvn</id>
<name>Repository for JDK 1.8 builds</name>
<url>http://mvnrepository.com</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
</profile>
<profile>
<id>spring</id>
<activation>
<jdk>1.8</jdk>
</activation>
<repository>
<id>spring</id>
<name>spring-central</name>
<url>https://repo.spring.io/libs-milestone</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>

</profile>
</profiles>
<activeProfiles>
<activeProfile>ali</activeProfile>
<activeProfile>spring</activeProfile>
<activeProfile>mvn</activeProfile>

</activeProfiles>

配置好之后将ide的maven路径修改
![](https://s4.51cto.com/images/blog/202010/17/f0d678a24b400f286f6b608b3b783aec.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
刷新maven配置
![刷新配置](https://s4.51cto.com/images/blog/202010/17/2066bfc32af97c0d6540bea7018c3d21.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
上述操作之后还是爆红,实际上maven仓库里面有了对应的jar包了,此时只能命令行执行mvn clean compile 或者mvn clean install 看控制台错误,检查报错的jar包是不是自己公司的内部jar包,如果是,找到对应jar包的版本路径和实际maven的路径 版本是否一一对应
![](https://s4.51cto.com/images/blog/202010/17/f30392ba94bc7503ee5d7e1fcdb3fc2c.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
上图中的common 1.0在我本地不存在,最后找到pom文件检查,发现现在的版本是1.0-SNAPSHOT,改完版本重新执行maven clean installl就可以了。为什么别人的可以,是因为别人在改版本之前已经编译过了,有了对应的jar包在本地仓库了所以别人的正常你的不正常,加载缓慢重启ide重新更新即可。
标签: