Maven 配置国内仓库地址

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/ysl19910806/article/details/94652152

我们在日常开发使用maven下载jar包速度会很慢,原因是maven默认的仓库地址是国外的,所以速度很慢,解决这个问题我们只需要修改maven仓库地址即可。

maven下载jar包时会优先去

C:\Users\用户\.m2\路径下查找setting.xml文件,

如果这里没有找到,会去我们在eclipse、idea中配置的maven目录中去查找

D:\apache-maven-3.6.1-bin\apache-maven-3.6.1\conf\setting.xml

修改为国内仓库地址,只需在setting.xml中添加以下配置即可。

 <mirrors>
        <mirror>  
		  <id>alimaven</id>  
		  <name>aliyun maven</name>  
		  <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
		  <mirrorOf>central</mirrorOf>          
		</mirror> 
		<mirror>
			<id>ui</id>
			<mirrorOf>central</mirrorOf>
			<name>Human Readable Name for this Mirror.</name>
			<url>http://uk.maven.org/maven2/</url>
		</mirror>
		<mirror>
            <id>osc</id>
            <mirrorOf>central</mirrorOf>
            <url>http://maven.oschina.net/content/groups/public/</url>
        </mirror>
        <mirror>
            <id>osc_thirdparty</id>
            <mirrorOf>thirdparty</mirrorOf>
            <url>http://maven.oschina.net/content/repositories/thirdparty/</url>
        </mirror>
  </mirrors>

完整配置

<?xml version="1.0" encoding="UTF-8"?>

<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">
	<pluginGroups>
		<!-- pluginGroup | Specifies a further group identifier to use for plugin 
			lookup. <pluginGroup>com.your.plugins</pluginGroup> -->
		<pluginGroup>org.mortbay.jetty</pluginGroup>
	</pluginGroups>

	<!-- proxies | This is a list of proxies which can be used on this machine 
		to connect to the network. | Unless otherwise specified (by system property 
		or command-line switch), the first proxy | specification in this list marked 
		as active will be used. | -->
	<proxies>
		<!-- proxy | Specification for one proxy, to be used in connecting to the 
			network. | <proxy> <id>optional</id> <active>true</active> <protocol>http</protocol> 
			<username>proxyuser</username> <password>proxypass</password> <host>proxy.host.net</host> 
			<port>80</port> <nonProxyHosts>local.net|some.host.com</nonProxyHosts> </proxy> -->
	</proxies>

	<!-- servers | This is a list of authentication profiles, keyed by the server-id 
		used within the system. | Authentication profiles can be used whenever maven 
		must make a connection to a remote server. | -->
	<servers>
		<!-- server | Specifies the authentication information to use when connecting 
			to a particular server, identified by | a unique name within the system (referred 
			to by the 'id' attribute below). | | NOTE: You should either specify username/password 
			OR privateKey/passphrase, since these pairings are | used together. | <server> 
			<id>deploymentRepo</id> <username>repouser</username> <password>repopwd</password> 
			</server> -->

		<!-- Another sample, using keys to authenticate. <server> <id>siteServer</id> 
			<privateKey>/path/to/private/key</privateKey> <passphrase>optional; leave 
			empty if not used.</passphrase> </server> -->
		<server>
			<id>releases</id>
			<username>ali</username>
			<password>ali</password>
		</server>
		<server>
			<id>Snapshots</id>
			<username>ali</username>
			<password>ali</password>
		</server>
	</servers>

	<!-- mirrors | This is a list of mirrors to be used in downloading artifacts 
		from remote repositories. | | It works like this: a POM may declare a repository 
		to use in resolving certain artifacts. | However, this repository may have 
		problems with heavy traffic at times, so people have mirrored | it to several 
		places. | | That repository definition will have a unique id, so we can create 
		a mirror reference for that | repository, to be used as an alternate download 
		site. The mirror site will be the preferred | server for that repository. 
		| -->
	<mirrors>
		<!-- mirror | Specifies a repository mirror site to use instead of a given 
			repository. The repository that | this mirror serves has an ID that matches 
			the mirrorOf element of this mirror. IDs are used | for inheritance and direct 
			lookup purposes, and must be unique across the set of mirrors. | <mirror> 
			<id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable 
			Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> 
			</mirror> -->
		<mirror>
			<!--This sends everything else to /public -->
			<id>nexus</id>
			<mirrorOf>*</mirrorOf>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
		</mirror>
		<mirror>
			<!--This is used to direct the public snapshots repo in the profile below 
				over to a different nexus group -->
			<id>nexus-public-snapshots</id>
			<mirrorOf>public-snapshots</mirrorOf>
			<url>http://maven.aliyun.com/nexus/content/repositories/snapshots/</url>
		</mirror>
	</mirrors>

	<profiles>
		<profile>
			<id>development</id>
			<repositories>
				<repository>
					<id>central</id>
					<url>http://central</url>
					<releases>
						<enabled>true</enabled>
						<updatePolicy>always</updatePolicy>
					</releases>
					<snapshots>
						<enabled>true</enabled>
						<updatePolicy>always</updatePolicy>
					</snapshots>
				</repository>
			</repositories>
			<pluginRepositories>
				<pluginRepository>
					<id>central</id>
					<url>http://central</url>
					<releases>
						<enabled>true</enabled>
						<updatePolicy>always</updatePolicy>
					</releases>
					<snapshots>
						<enabled>true</enabled>
						<updatePolicy>always</updatePolicy>
					</snapshots>
				</pluginRepository>
			</pluginRepositories>
		</profile>
		<profile>
			<!--this profile will allow snapshots to be searched when activated -->
			<id>public-snapshots</id>
			<repositories>
				<repository>
					<id>public-snapshots</id>
					<url>http://public-snapshots</url>
					<releases>
						<enabled>false</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
						<updatePolicy>always</updatePolicy>
					</snapshots>
				</repository>
			</repositories>
			<pluginRepositories>
				<pluginRepository>
					<id>public-snapshots</id>
					<url>http://public-snapshots</url>
					<releases>
						<enabled>false</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
						<updatePolicy>always</updatePolicy>
					</snapshots>
				</pluginRepository>
			</pluginRepositories>
		</profile>
	</profiles>
	<activeProfiles>
		<activeProfile>development</activeProfile>
		<activeProfile>public-snapshots</activeProfile>
	</activeProfiles>
</settings>

 

猜你喜欢

转载自blog.csdn.net/ysl19910806/article/details/94652152