本地仓库及远程仓库配置实践
作者:互联网
1.本地仓库配置
默认情况下,maven本地仓库默认地址是~/.m2/respository目录,这个默认我们也可以在~/.m2/settings.xml文件中进行修改:
<localRepository>本地仓库地址</localRepository>
如:
<localRepository>C:\Users\allen\.m2\repository</localRepository>
项目中设置maven时,选择本地仓库
2.远程仓库的配置
方式一:POM文件张工添加依赖
删除.m2路径下仓库文件或者重命名后,在POM文件中添加下列依赖
<dependencies> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>2.0.1</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.2.13.RELEASE</version> </dependency> </dependencies> <repositories> <repository> <id>aliyun-release</id> <url>https://maven.aliyun.com/repository/public</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories>
项目路径下 打开cmd 输入mvn compile
稍等片刻后(看网速),.m2路径下增加了repository仓库
方式二:settings.xml文件添加镜像方式
<!--远程仓库配置--> <mirrors> <mirror> <id>mirror-aliyun-releases</id> <mirrorOf>*</mirrorOf> <name>aliyun maven mirror</name> <url>https://maven.aliyun.com/repository/public</url> <blocked>true</blocked> </mirror> </mirrors>
POM文件中保留依赖
<dependencies> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>2.0.1</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.2.13.RELEASE</version> </dependency> </dependencies>
同样执行mvn compile时报错
网上搜索解决办法:在POM文件中添加正确的依赖即可
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</dependency>
标签:本地,仓库,boot,maven,POM,aliyun,m2,远程 来源: https://www.cnblogs.com/allencxw/p/16255926.html