maven 仓库配置

仓库的分类:本地仓库和远程仓库;仓库中保存的内容有:maven自身所需要的插件、第三方(第一方:jdk;第二方:开发者;第三方:其他人)框架或工具的jar包,我们自己开发的maven工程;

本地仓库

默认是在~/.m2/repository/,~代表的是用户目录;

配置比较简单,只要在xml中配置如下:

 <!-- 本地仓库的位置 -->
    <localRepository>E:/Data/Maven/repository</localRepository>

远程仓库

分为中央仓库、中央仓库镜像和私服。默认是maven的中央仓库:https://mvnrepository.com/

远程仓库配置:

<repositories>
    <repository>
        <id>central</id>
        <name>Central Repository</name>
        <url>https://repo.maven.apache.org/maven2</url>
        <layout>default</layout>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

 id:该远程仓库的唯一标识;

name:远程仓库的名称;

使该仓库生效:

<activeProfile>central</activeProfile>   

 

配置镜像:

把对远程仓库的请求转换到对应的镜像地址的请求。每个远程仓库都会有一个id,这样我们就可以创建自己的mirror来关联到该仓库,那么以后需要从远程仓库下载工件的时候Maven就可以从我们定义好的mirror站点来下载,这可以很好的缓解我们远程仓库的压力。在我们定义的mirror中每个远程仓库都只能有一个mirror与它关联,也就是说你不能同时配置多个mirror的mirrorOf指向同一个repositoryId;

1 <mirrors>
2     <mirror>
3       <id>internal-repository</id>
4       <name>Maven Repository Manager running on repo.mycompany.com</name>
5       <url>http://repo.mycompany.com/proxy</url>
6       <mirrorOf>*</mirrorOf>
7     </mirror>
8   </mirrors>

id: 镜像的唯一标识

mirrorOf: 指定镜像规则,什么情况下从镜像仓库拉取,官方文档

  • *: 匹配所有,所有内容都从镜像拉取
  • external:*: 除了本地缓存的所有从镜像仓库拉取
  • repo,repo1: repo 或者 repo1 ,这里的 repo 指的仓库 ID
  • *,!repo1: 除了 repo1 的所有仓库

name: 名称描述

url: 地址

阿里云镜像配置:

1 <mirror>
2       <id>alimaven</id>
3       <name>aliyun maven</name>
4       <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
5       <mirrorOf>central</mirrorOf>       
6     </mirror>

其他标签说明:

server

如果仓库地址是个私服;需要配置 server

配置分发构建到私服的验证,在setting.xml文件的<servers></servers>标签内插入如下代码段

<server>
            <id>server001</id>
            <!--鉴权用户名。鉴权用户名和鉴权密码表示服务器认证所需要的登录名和密码。-->
            <username>my_login</username>
            <!--鉴权密码。鉴权用户名和鉴权密码表示服务器认证所需要的登录名和密码。密码加密功能已被添加到2.1.0+。详情请访问密码加密页面-->
            <password>my_password</password>
        </server>

pluginGroups:

  • 元素里包含了一个pluginGroup列表。默认maven中有org.apache.maven.pluginsorg.codehaus.mojo两个pluginGroup。表示当通过plugin的前缀来解析plugin的时候到哪里寻找。pluginGroup元素指定的是plugin的groupId
  • 如果pom,xml中的plugin没有设置指定groupId,熟悉maven的都知道我们引入以来至少需要groupId和artifactId的。但是下面的插件中没有。这个时候maven就会获取pluginGroupspluginGroup列表和配置中artifactId进行一一匹配。匹配到下载。
  • jetty 插件的配置 :为了更明确的指向这个groupId是我们需要的插件,唯一的办法就是在settings.xml也做如下设置:
<pluginGroups>                                 
    <pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>

 完整的setting配置:

<?xml version="1.0" encoding="UTF-8"?>
<settings>
<localRepository>E:/Data/Maven/repository</localRepository>
<pluginGroups>                                 
    <pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>

 <mirrors>
    <mirror>
      <id>nexus</id>  
      <mirrorOf>*</mirrorOf>  
      <url>http://nexus.d.xxx.net/nexus/content/groups/public</url> <!--镜像地址-->
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <id>development</id>
      <repositories> <!-- 构件的仓库-->
        <repository>
          <id>central</id>
          <url>http://nexus</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories> <!--插件的仓库-->
        <pluginRepository>
          <id>central</id>
          <url>http://nexus</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>development</activeProfile> <!-- 对于所有的pom,上边定义的id=development的profile都是活跃状态的-->
  </activeProfiles>
 
  <servers>
    <server>
      <id>archiva.internal</id>  <!--release版本的用户名和密码-->
      <username>yangwenqiang</username>
      <password>pwdpwd</password>
    </server>
    <server>
      <id>archiva.snapshots</id> <!-- snapshot版本的用户名和密码-->
      <username>yangwenqiang</username>
      <password>pwdpwd</password>
    </server>
  </servers>

</settings>

 

posted @ 2022-01-30 13:34  啄木鸟伍迪  阅读(2159)  评论(0编辑  收藏  举报
//火箭 GenerateContentList();