Maven setting配置镜像仓库的方法步骤

1.配置IDE构建的Maven存放目录(解压目录)

2.配置IDE的User setting file路径,修改setting配置文件

配置本地仓库

<!--自定义本地仓库路径-->
<localRepository>E:\JAVA\Maven</localRepository> 

配置mirrors远程镜像(一般配置一到两个镜像) 

<mirrors>
   <mirror>
    <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/mvn/view</url>
    <mirrorOf>central</mirrorOf>
  </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>
  <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>central</id>
    <name>Maven Repository Switchboard</name>
    <url>http://repo1.maven.org/maven2/</url>
    <mirrorOf>central</mirrorOf>
  </mirror>
  <mirror>
    <id>repo2</id>
    <mirrorOf>central</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://repo2.maven.org/maven2/</url>
  </mirror>
</mirrors>

配置profiles构建  

<profile>
  <id>jdk18</id>
  <activation>
    <jdk>1.8</jdk>
    <activeByDefault>true</activeByDefault>
  </activation>
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
  </properties>
</profile>

国内Maven镜像仓库值得收藏 

<mirrors>
   <mirror>
    <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/mvn/view</url>
    <mirrorOf>central</mirrorOf>
  </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>
  <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>central</id>
    <name>Maven Repository Switchboard</name>
    <url>http://repo1.maven.org/maven2/</url>
    <mirrorOf>central</mirrorOf>
  </mirror>
  <mirror>
    <id>repo2</id>
    <mirrorOf>central</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://repo2.maven.org/maven2/</url>
  </mirror>
</mirrors>

 完整setting配置  

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

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 | 1. User Level. This settings.xml file provides configuration for a single user,
 |         and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |         NOTE: This location can be overridden with the CLI option:
 |
 |         -s /path/to/user/settings.xml
 |
 | 2. Global Level. This settings.xml file provides configuration for all Maven
 |         users on a machine (assuming they're all using the same Maven
 |         installation). It's normally provided in
 |         ${maven.conf}/settings.xml.
 |
 |         NOTE: This location can be overridden with the CLI option:
 |
 |         -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<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">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <localRepository>D:\Program Files\Develop\Portable\localRepository</localRepository>

  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- 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>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</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>
    -->
  </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>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/mvn/view</url>
      <mirrorOf>central</mirrorOf>
    </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>
    <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>central</id>
      <name>Maven Repository Switchboard</name>
      <url>http://repo1.maven.org/maven2/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
    <mirror>
      <id>repo2</id>
      <mirrorOf>central</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://repo2.maven.org/maven2/</url>
    </mirror>
  </mirrors>

  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |    repositories, plugin repositories, and free-form properties to be used as configuration
   |    variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
     <id>jdk-1.4</id>

     <activation>
      <jdk>1.4</jdk>
     </activation>

     <repositories>
      <repository>
       <id>jdk14</id>
       <name>Repository for JDK 1.4 builds</name>
       <url>http://www.myhost.com/maven/jdk14</url>
       <layout>default</layout>
       <snapshotPolicy>always</snapshotPolicy>
      </repository>
     </repositories>
    </profile>
    -->
    <profile>
      <id>jdk18</id>
      <activation>
        <jdk>1.8</jdk>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
      </properties>
    </profile>

    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |  <groupId>org.myco.myplugins</groupId>
     |  <artifactId>myplugin</artifactId>
     |
     |  <configuration>
     |   <tomcatLocation>${tomcatPath}</tomcatLocation>
     |  </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |    anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
     <id>env-dev</id>

     <activation>
      <property>
       <name>target-env</name>
       <value>dev</value>
      </property>
     </activation>

     <properties>
      <tomcatPath>/path/to/tomcat/instance</tomcatPath>
     </properties>
    </profile>
    -->
  </profiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
   <activeProfile>alwaysActiveProfile</activeProfile>
   <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • Maven setting.xml配置文件详解

    maven的配置文件settings.xml存在于两个地方: 1.安装的地方:${M2_HOME}/conf/settings.xml 2.用户的目录:${user.home}/.m2/settings.xml 前者又被叫做全局配置,对操作系统的所有使用者生效:后者被称为用户配置,只对当前操作系统的使用者生效.如果两者都存在,它们的内容将被合并,并且用户范围的settings.xml会覆盖全局的settings.xml. Maven安装后,用户目录下不会自动生成settings.xml,只有全局

  • 详解maven的setting配置文件中mirror和repository的区别

    当maven需要到的依赖jar包不在本地仓库时, 就需要到远程仓库下载 . 这个时候如果mavensetting.xml中配置了镜像 , 而且镜像配置的规则中匹配到目标仓库时 , maven认为目标仓库被镜像了, 不会再去被镜像仓库下载依赖jar包, 而是直接去镜像仓库下载. 简单而言, mirror可以拦截对远程仓库的请求 , 改变对目标仓库的下载地址 repository repository就是个仓库. maven里有两种仓库,本地仓库和远程仓库. 远程仓库相当于公共的仓库,大家都能看到.

  • Maven默认中央仓库(settings.xml 配置详解)

    Maven的安装 安装Maven之前要确保已经安装好了jdk,并且配置好了环境变量JAVA_HOME.具体安装步骤如下: 1. 从apache网上下载maven项目的压缩包.下载地址为:http://maven.apache.org/download.html.比如现在最新的Maven版本是3.0.4,那么我下载好的安装文件就是apache-maven-3.0.4.zip. 2. 将下载后的压缩包解压到Maven的安装目录,比如说是D:\\develop,那么解压后就是D:\\develop\\

  • Maven setting配置镜像仓库的方法步骤

    1.配置IDE构建的Maven存放目录(解压目录) 2.配置IDE的User setting file路径,修改setting配置文件 配置本地仓库 <!--自定义本地仓库路径--> <localRepository>E:\JAVA\Maven</localRepository> 配置mirrors远程镜像(一般配置一到两个镜像) <mirrors> <mirror> <id>alimaven</id> <name&

  • maven配置阿里仓库的方法步骤

    大家使用maven下载jar包会很慢,最主要的原因是maven的仓库在英国,但如果使用了阿里的仓库下载jar包就会变得很便捷.下面是如和配置阿里的仓库. <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/repos

  • maven配置本地仓库的方法步骤

    目录 1.下载apache-maven-3.6.3-bin.zip 2.配置环境变量 3.测试 4.配置本地仓库 5.输入命令 本文主要介绍了maven配置本地仓库,分享给大家,具体如下: 官网http://maven.apache.org/download.cgi 1.下载apache-maven-3.6.3-bin.zip 然后解压放在本地盘(我放在了C盘,重命名为maven).然后再新建一个文件夹,命名为:maven-repository,作为本地仓库. 2.配置环境变量 在系统属性-环境

  • 使用maven命令安装jar包到本地仓库的方法步骤

    第三方jar包在开发工具中引入后编译没问题, 启动调试包括打包时会提示找不到jar包的错误.需要上传到maven仓库中,并在pom文件内引入. maven命令: 安装指定文件到本地仓库命令:mvn install:install-file -DgroupId=<groupId> : 设置上传到仓库的包名 -DartifactId=<artifactId> : 设置该包所属的模块名 -Dversion=1.0.0 : 设置该包的版本号 -Dpackaging=jar : 设置该包的类

  • 详解maven配置多仓库的方法示例

    刚接触maven就是在公司里配置好的,所以一直以来使用都没毛病,所以一直没有去动这些固有的东西. 但是,后来把公司的电脑拿回家之后,发现有的东西就搞不起来了.原因也看一下就明白了,因为在公司的时候用的是公司的maven私服,所以回家后,用不了也是正常. 但是,真的脱离了公司,自己就不能工作了吗?不可能吧. 难道一下开源工具都必须要依赖于公司的网络? 这明显是不合理的. 那么,就扯出本次文章的意义了,在家里,自然是要公有的maven仓库了,那么,怎样配置maven仓库才能让自己用起来顺心呢? 1.

  • 在IDEA里gradle配置和使用的方法步骤

    前言 有人说Gradle使用groovy语言编写,简单,明了没像maven使用xml臃肿,其实我倒不觉得,我觉得maven挺好的,管理jar依赖和项目生命周期挺方便的,我使用gradle只是因为公司用,不然我估计不会学习gradle.下面是gradle的优点,自己斟酌吧. 1. 按约定声明构建和建设: 2. 强大的支持多工程的构建: 3. 强大的依赖管理(基于Apache Ivy),提供最大的便利去构建工程: 4. 全力支持已有的 Maven 或者Ivy仓库基础建设: 5. 支持传递性依赖管理,

  • PyCharm 2020.2下配置Anaconda环境的方法步骤

    最近在学习关于Python数据分析与挖掘方面的知识,在学习到Python数据分析工具方面时,需要安装一些第三方扩展库来增强Python的数据分析能力,刚开始我就按照最一般的方法,使用pip包管理工具来安装,但是总是遇到各种错误,失败了很多次,耐心都快被耗尽了. 初次接触这方面的内容,不是太了解,就请教了老师,老师就给我推荐直接安装Anaconda来使用.Anaconda指的是一个开源的Python发行版本,其包含了conda.Python等180多个科学包及其依赖项(我也不是很懂).废话不多说,

  • Intellij IDEA快速实现Docker镜像部署的方法步骤

    目录 1.Docker开启远程访问 2.Intellij IDEA安装Docker插件 3.spring boot服务Docker部署 4.创建Docker镜像 参考: 1.Docker开启远程访问 [root@izwz9eftauv7x69f5jvi96z docker]# vim /lib/systemd/system/docker.service #修改ExecStart这行 ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:

  • Ubuntu18.04下安装配置SSH服务的方法步骤

    安装ssh工具 1.打开终端键入如下命令: apt-get update apt-get install openssh-server 2.选择Y继续执行: 启动SSH服务 1.键入如下命令: /etc/init.d/ssh start 注:重启命令与关闭命令如下: /etc/init.d/ssh restart #重启SSH服务 /etc/init.d/ssh stop #关闭SSH服务 2.查看进程,检查是否启动成功,键入如下命令: ps -e | grep sshd 有了进程才能进行SSH

  • VSCode配置C++环境的方法步骤(MSVC)

     最近心血来潮,想用一下微软的VSCode写一下C++,然而第一步就卡住了,竟然不会配置C++环境,陆陆续续搞了两天,总算是弄明白了,网上msvc教程比较少,就打算分享出来,也记录下自己的历程.  先说说我的理解吧,Visual Studio Code和visual studio不同,后者是属于IDE是个集成开发环境,下载好基本就能直接用来写C++等:  而Visual Studio Code(以下简称VSC)是一个编辑器,简单来说和windows电脑上的那个看.txt文件的记事本一个类别,然而

随机推荐