最近做项目时直接复制了别人的pom文件的内容,可是复制过来的Maven依赖一直爆红,不下载依赖。
<dependencyManagement>
<dependencies>
<!--spring boot 2.2.2-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
因为之前没有学习过maven,都是直接复制依赖就可以用了,所以对maven的各种标签不是很熟悉。
开始以为是中央仓库太卡了下不动,所以找了各种办法,网上比较多的说法也是说使用aliyun的镜像仓库。后来我又是配置mirror,又是重下载新版本maven的。
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
一顿操作后都不行.
最后还是不行最后发现根本就不是卡住下不动,而是连下载都没有开始,于是开始改标签。最终把dependencyManagement标签删掉后居然开始下载了。后面查了一下才发现dependencyManagement用于父工程管理依赖的,用于统一管理jar的版本,在父工程的时候只是用来声明,并不会下载,只有子工程要用到的时候才会去下载。而本地又没用这些依赖的jar版本,所以才会一直爆红。
解决办法是将dependencyManagement标签去掉,jar包就会开始下载了,等下载完成后再加上dependencyManagement。
<dependencies>
<!--spring boot 2.2.2-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>