maven 公网 setting.xml 配置(apache-maven-3.0.3)

本文分享了一种优化Maven设置.xml的方法,通过配置数据源、镜像和离线模式,减少公网连接等待时间,提高构建速度。

公网配置项目,不是很方便,总是需要等待很长时间....

下面是我自己调试过,比较好使的数据源配置、加载方式

<?xml version="1.0" encoding="UTF-8"?>
<settings
 xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"
 xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <localRepository>D:\java\repository</localRepository>
 <!-- offline
    | Determines whether maven should attempt to connect to the network when executing a build.
    | This will have an effect on artifact downloads, artifact deployment, and others.
    |
    | Default: false-->
 <offline>true</offline>
 <profiles>
  <profile>
   <id>jdRepository</id>
   <repositories>
      <repository>
       <id>jboss-cache</id>
       <name>jboss-cache</name>
       <url>http://repository.jboss.org/maven2</url>
      </repository>
      <repository>
       <id>mvnsearch</id>
       <name>mvnsearch Maven Repository</name>
     <url>http://www.mvnsearch.org/maven2</url>
    </repository>
    <repository>
     <id>ibiblio</id>
     <name>ibiblio Maven Repository</name>
     <url>http://www.ibiblio.org/maven2</url>
    </repository>
    <repository>
     <id>mirrors.ibiblio</id>
     <name>mirrors.ibiblio Maven Repository</name>
     <url>http://mirrors.ibiblio.org/pub/mirrors/maven2</url>
    </repository>
    <repository>
     <id>repo.springsource.org</id>
     <name>repo.springsource.org-releases</name>
     <url>http://repo.springsource.org/libs-milestone-local</url>
     <snapshots>
      <enabled>false</enabled>
     </snapshots>
    </repository>
   </repositories>
   <pluginRepositories>
    <pluginRepository>
     <id>central</id>
     <name>Maven Plugin Repository</name>
     <url>http://repo1.maven.org/maven2</url>
     <layout>default</layout>
     <snapshots>
      <enabled>false</enabled>
     </snapshots>
     <releases>
      <updatePolicy>never</updatePolicy>
     </releases>
    </pluginRepository>
   </pluginRepositories>
  </profile>
 </profiles>
 <mirrors>
  <mirror>
     <id>repo2</id>
     <mirrorOf>central</mirrorOf>
     <name>Human Readable Name for this Mirror.</name>
     <url>http://repo2.maven.org/maven2/</url>
   </mirror>
  <mirror>
     <id>net-cn</id>
     <mirrorOf>central</mirrorOf>
     <name>Human Readable Name for this Mirror.</name>
     <url>http://maven.net.cn/content/groups/public/</url>
   </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>ibiblio</id>
     <mirrorOf>central</mirrorOf>
     <name>Human Readable Name for this Mirror.</name>
    <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
   </mirror>
  <mirror>
    <id>jboss-public-repository-group</id>
    <mirrorOf>central</mirrorOf>
    <name>JBoss Public Repository Group</name>
   <url>http://repository.jboss.org/nexus/content/groups/public</url>
  </mirror>
 </mirrors>
 <activeProfiles>
  <activeProfile>jdRepository</activeProfile>
 </activeProfiles>
</settings>

无法从 `https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip` 下载 ZIP 分发,可能是由网络问题、中央仓库可访问等原因导致的。可以尝试以下解决办法: #### 使用镜像仓库 中央仓库在国外,为了方便访问,可以使用国内的镜像仓库,其内容与中央仓库内容一致,需要设置 Maven 的 `setting.xml` 配置。示例如下: ```xml <mirrors> <mirror> <id>CN</id> <mirrorOf>central</mirrorOf> <name>OSChina Central</name> <url>http://maven.oschina.net/content/groups/public/</url> </mirror> <!-- 也可以使用其他镜像 --> <mirror> <id>nexus</id> <mirrorOf>central</mirrorOf> <name>Nexus 197</name> <url>http://nexus.healthbok-inc.com:8080/content/groups/public/</url> </mirror> </mirrors> ``` 上述配置中,`mirrorOf` 表示凡是访问 `central` 仓库的,都使用以下定义的镜像仓库,也可以使用 `*` 表示所有仓库访问都转为使用此镜像仓库。 #### 手动下载并安装到本地仓库 如果网络问题仍然无法解决,可以手动从其他可靠渠道下载 `apache-maven-3.9.11-bin.zip` 文件。然后使用 Maven 提供的 `install:install-file` 插件目标将其注册到本地 `.m2/repository` 中。基本语法如下: ```bash mvn install:install-file \ -Dfile=<path-to-file> \ -DgroupId=org.apache.maven \ -DartifactId=apache-maven \ -Dversion=3.9.11 \ -Dpackaging=zip \ -DgeneratePom=true ``` 其中,`<path-to-file>` 需要替换为你下载的 `apache-maven-3.9.11-bin.zip` 文件的实际路径。 #### 使用公司内部的 Maven 私服 如果所在公司有内部的 Maven 私服,可以将 Maven 配置为从私服下载依赖。需要在 `settings.xml` 中配置私服的信息,并且在 `pom.xml` 中配置相关的仓库信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值