欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

阿里云镜像站怎么下载(阿里云服务器下载镜像)

程序员文章站 2024-02-09 19:33:04
单独配置华为云 mirror准备工作使用前请确保您已安装jdk及maven。如果您尚未安装,可以点击下面链接下载安装:jdk官网下载地址:https://www.oracle.com/technetw...

单独配置华为云 mirror

准备工作使用前请确保您已安装jdk及maven。如果您尚未安装,可以点击下面链接下载安装:jdk官网下载地址:
https://www.oracle.com/technetwork/java/javase/downloads/index.htmlmaven加速地址:https://repo.huaweicloud.com/apache/maven/maven-3/

使用说明点击此处 下载settings.xml文件,覆盖<maven安装目录>/conf/settings.xml文件即可。如果您不想覆盖配置文件,可以手动在settings.xml文件中的mirrors节点中添加如下内容:

<mirror>
    <id>huaweicloud</id>
    <mirrorof>*</mirrorof>
    <url>https://repo.huaweicloud.com/repository/maven/</url>
</mirror>

相关网址maven官方地址:
https://maven.apache.orgmaven搜索地址:http://mvnrepository.com

单独配置华为私有库依赖

1.在mirrors节点中添加如下配置:(可选,使用华为开源镜像站加速下载开源组件)

    <mirror>
        <id>z_mirrors</id>
        <mirrorof>*,!releases,!snapshots</mirrorof>
        <url>https://repo.huaweicloud.com/repository/maven/</url>
    </mirror>

2.在servers节点中添加如下配置:(password从下载的settings.xml文件中获取)


    <server>
        <id>releases</id>
        <username>088dbeef3980f4050f6fc007779eab60_088dbef03980f2d21f98c007dcbde04f</username>
        <password>************</password>
    </server>
    <server>
        <id>snapshots</id>
        <username>088dbeef3980f4050f6fc007779eab60_088dbef03980f2d21f98c007dcbde04f</username>
        <password>************</password>
    </server>

3.在profiles节点中添加如下配置

    <profile>
        <id>myprofile</id>
        <repositories>
            <repository>
                <id>releases</id>
                <url>https://devrepo.devcloud.cn-north-4.huaweicloud.com/07/nexus/content/repositories/088dbeef3980f4050f6fc007779eab60_1_0/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>snapshots</id>
                <url>https://devrepo.devcloud.cn-north-4.huaweicloud.com/07/nexus/content/repositories/088dbeef3980f4050f6fc007779eab60_2_0/</url>
                <releases>
                    <enabled>false</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
    </profile>

单独配置阿里云 mirror

打开maven的配置文件(windows机器一般在maven安装目录的conf/settings.xml),在<mirrors></mirrors>标签中添加mirror子节点:

<mirror>
    <id>aliyunmaven</id>
    <mirrorof>*</mirrorof>
    <name>阿里云公共仓库</name>
    <url>https://maven.aliyun.com/repository/public</url>
</mirror>

如果想使用其它代理仓库,可在<repositories></repositories>节点中加入对应的仓库使用地址。以使用spring代理仓为例:

<repository>
    <id>spring</id>
    <url>https://maven.aliyun.com/repository/spring</url>
    <releases>
        <enabled>true</enabled>
    </releases>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>

单独配置阿里云效私有库依赖

1.在mirrors节点中添加如下配置:(可选,使用阿里开源镜像站加速下载开源组件)

        <mirror>
            <id>mirror</id>
            <mirrorof>!rdc-releases,!rdc-snapshots</mirrorof>
            <url>https://maven.aliyun.com/repository/public</url>
        </mirror>
  1. 在settings.xml中添加认证信息
    在maven的的默认settings.xml中找到servers的部分,添加一个server配置如下。
<servers>
    <server>
        <id>rdc-releases</id>
        <username>***</username>
        <password>******</password>
    </server>
    <server>
        <id>rdc-snapshots</id>
        <username>***</username>
        <password>******</password>
    </server>
</servers>

3.在profiles节点添加如下配置, 其中 repository 是顺序搜索下载包的.

<profile>
            <id>rdc-private-repo</id>
            <repositories>
                <repository>
                    <id>rdc-releases</id>
                    <url>https://repo.rdc.aliyun.com/repository/78947-release-cfzlq7/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>rdc-snapshots</id>
                    <url>https://repo.rdc.aliyun.com/repository/78947-snapshot-xtubsz/</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginrepositories>
                <pluginrepository>
                    <id>rdc-releases</id>
                    <url>https://repo.rdc.aliyun.com/repository/78947-release-cfzlq7/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginrepository>
                <pluginrepository>
                    <id>rdc-snapshots</id>
                    <url>https://repo.rdc.aliyun.com/repository/78947-snapshot-xtubsz/</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginrepository>
            </pluginrepositories>
        </profile>
  1. 制品上传配置
    配置好了settings.xml后,在代码库根目录下的pom.xml加入以下配置:
<!-- 需要发布二方包 则打开下列的配置 -->
<distributionmanagement>
    <repository>
        <id>rdc-releases</id>
        <url>https://repo.rdc.aliyun.com/repository/78947-release-cfzlq7/</url>
    </repository>
    <snapshotrepository>
        <id>rdc-snapshots</id>
        <url>https://repo.rdc.aliyun.com/repository/78947-snapshot-xtubsz/</url>
    </snapshotrepository>
</distributionmanagement>

然后运行以下命令即可将制品推送到私有仓库中:

$ mvn clean deploy -dskiptests

maven中-dskiptests和-dmaven.test.skip=true的区别在使用mvn package进行编译、打包时,maven会执行src/test/java中的junit测试用例,有时为了跳过测试,会使用参数-dskiptests和-dmaven.test.skip=true,这两个参数的主要区别是:

-dskiptests,不执行测试用例,但编译测试用例类生成相应的class文件至target/test-classes下。-dmaven.test.skip=true,不执行测试用例,也不编译测试用例类。

关于 mirror 的说明

虽然mirrors可以配置多个子节点,但是它只会使用其中的一个节点,即默认情况下配置多个mirror的情况下,只有第一个生效,只有当前一个mirror无法连接的时候,才会去找后一个;而我们想要的效果是:当a.jar在第一个mirror中不存在的时候,maven会去第二个mirror中查询下载,但是maven不会这样做!

关于 properties 的说明

properties作用:对应profile的扩展属性列表。maven属性和ant中的属性一样,可以用来存放一些值。这些值可以在pom.xml中的任何地方使用标记${x}来使用,这里x是指属性的名称。属性有五种不同的形式,并且都能在settings.xml文件中访问。

<!-- 
  1. env.x: 在一个变量前加上"env."的前缀,会返回一个shell环境变量。例如,"env.path"指代了$path环境变量(在windows上是%path%)。 
  2. project.x:指代了pom中对应的元素值。例如: <project><version>1.0</version></project>通过${project.version}获得version的值。 
  3. settings.x: 指代了settings.xml中对应元素的值。例如:<settings><offline>false</offline></settings>通过 ${settings.offline}获得offline的值。 
  4. java system properties: 所有可通过java.lang.system.getproperties()访问的属性都能在pom中使用该形式访问,例如 ${java.home}。 
  5. x: 在<properties/>元素中,或者外部文件中设置,以${somevar}的形式使用。
 -->

<properties>
  <user.install>${user.home}/our-project</user.install>
</properties>

配置了 阿里和华为云配置的综合案例

<?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></plugingroups>
    <proxies></proxies>
    <servers>
        <!-- 华为 rds -->
        <!-- id 需要和 settings profiles.profile.repository.id 和 project 下 distributionmanagement.repository.id 保持一致,  -->
        <server>
            <id>huawei-rdc-repository</id>
            <username>****yourname***</username>
            <password>****yourpassword******</password>
        </server>
        <server>
            <id>huawei-rdc-snapshots-repository</id>
            <username>****yourname***</username>
            <password>****yourpassword******</password>
        </server>
        <!-- 阿里 rds -->
        <server>
            <id>aliyun-rdc-repository</id>
            <username>****yourname***</username>
            <password>****yourpassword******</password>
        </server>
        <server>
            <id>aliyun-rdc-snapshots-repository</id>
            <username>****yourname***</username>
            <password>****yourpassword******</password>
        </server>
        <!-- 宝利 rds -->
        <server>
            <id>poly-rdc-repository</id>
            <username>admin</username>
            <password>ncl@1234</password>
        </server>
    </servers>
    <mirrors>
        <mirror>
            <id>huaweimirror</id>
            <name>华为云公共仓库</name>
            <mirrorof>central</mirrorof>
            <url>https://repo.huaweicloud.com/repository/maven/</url>
        </mirror>
        <mirror>
            <id>aliyunmirror</id>
            <name>阿里云公共仓库</name>
            <mirrorof>central</mirrorof>
            <url>https://maven.aliyun.com/repository/public</url>
        </mirror>
    </mirrors>
    <profiles>
        <profile>
            <id>default-profile</id>
            <properties>
                <my.repository.url>https://maven.aliyun.com/nexus/content/groups/public</my.repository.url>
            </properties>
            <repositories>
                <repository>
                    <id>central</id>
                    <url>${my.repository.url}</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>snapshots</id>
                    <url>${my.repository.url}</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginrepositories>
                <pluginrepository>
                    <id>central</id>
                    <url>${my.repository.url}</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginrepository>
                <pluginrepository>
                    <id>snapshots</id>
                    <url>${my.repository.url}</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginrepository>
            </pluginrepositories>
        </profile>
        <profile>
            <id>huawei-profile</id>
            <properties>
                <my.releases.url>https://devrepo.devcloud.cn-north-4.huaweicloud.com/07/nexus/content/repositories/088dbeef3980f4050f6fc007779eab60_1_0/</my.releases.url>
                <my.snapshots.url>https://devrepo.devcloud.cn-north-4.huaweicloud.com/07/nexus/content/repositories/088dbeef3980f4050f6fc007779eab60_2_0/</my.snapshots.url>
            </properties>
            <repositories>
                <repository>
                    <id>huawei-rdc-repository</id>
                    <url>${my.releases.url}</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>huawei-rdc-snapshots-repository</id>
                    <url>${my.snapshots.url}</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginrepositories>
                <pluginrepository>
                    <id>huawei-rdc-repository</id>
                    <url>${my.releases.url}</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginrepository>
                <pluginrepository>
                    <id>huawei-rdc-snapshots-repository</id>
                    <url>${my.snapshots.url}</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginrepository>
            </pluginrepositories>
        </profile>
        <profile>
            <id>aliyun-profile</id>
            <properties>
                <my.releases.url>https://repo.rdc.aliyun.com/repository/78947-release-cfzlq7/</my.releases.url>
                <my.snapshots.url>https://repo.rdc.aliyun.com/repository/78947-snapshot-xtubsz/</my.snapshots.url>
            </properties>
            <repositories>
                <repository>
                    <id>aliyun-rdc-repository</id>
                    <url>${my.releases.url}</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>aliyun-rdc-snapshots-repository</id>
                    <url>${my.snapshots.url}</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginrepositories>
                <pluginrepository>
                    <id>aliyun-rdc-repository</id>
                    <url>${my.releases.url}</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginrepository>
                <pluginrepository>
                    <id>aliyun-rdc-snapshots-repository</id>
                    <url>${my.snapshots.url}</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginrepository>
            </pluginrepositories>
        </profile>
        <profile>
            <id>poly-profile</id>
            <repositories>
                <!-- <repository><id>poly-repository</id><name>private maven</name><url>http://10.1.103.106:9080/repository/maven-public/</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository> -->
            </repositories>
            <pluginrepositories>
                <!-- <pluginrepository><id>poly-repository</id><name>private maven</name><url>http://10.1.103.106:9080/repository/maven-public/</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></pluginrepository> -->
            </pluginrepositories>
        </profile>
    </profiles>
    <activeprofiles>
        <activeprofile>default-profile</activeprofile>
        <!-- <activeprofile>huawei-profile</activeprofile> -->
        <activeprofile>aliyun-profile</activeprofile>
        <!-- <activeprofile>poly-profile</activeprofile> -->
    </activeprofiles>
</settings>

相关地址

https://mirrors.huaweicloud.com/