首页 > 其他分享 >Maven配置私有库

Maven配置私有库

时间:2023-08-11 13:22:15浏览次数:36  
标签:xml http Repository 私有 配置 仓库 Maven nexus pom

一、仓库

仓库类型:
本地仓库、远程中央仓库、公司自己搭建的私有仓库

寻找jar的基本优先级顺序:
本地仓库 > settings.xml的profile的仓库 > pom.xml的profile的仓库 >pom.xml的仓库 > 中央仓库

设置仓库的方式有两种,一种是在项目最顶级POM.xml中设置,另一种是在settings.xml中设置。

在POM.xml中设置:

<repositories>
<repository>
<id>nexus</id>
<name>Team Nexus Repository</name>
<url>http://192.168.100.100:8181/nexus/content/groups/public</url>
</repository>
<repository>
<id>thirdparty</id>
<name>Nexus thirdparty</name>
<url>http://192.168.100.100:8181/nexus/content/repositories/thirdparty/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>Team Nexus Repository</name>
<url>http://192.168.100.100:8181/nexus/content/groups/public</url>
</pluginRepository>
</pluginRepositories>

settings.xml中设定:

<?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">
<localRepository>/Users/本地仓库地址/Documents/repo</localRepository>
<pluginGroups></pluginGroups>
<proxies></proxies>
<servers>
<!--
发布到仓库中的配置,id要和distributionrepository保持一致
服务器要打包上传到私服时,设置私服的鉴权信息,否和报错 Return code is: 401, ReasonPhrase: Unauthorized
-->
<server>
<id>release</id>
<username>deployment</username>
<password>123456</password>
</server>
<server>
<id>snapshot</id>
<username>deployment</username>
<password>123456</password>
</server>
</servers>
<mirrors>
<!-- 设置多个mirrors镜像,镜像只会执行第一个位置mirror。-->
<!-- 配置的多个mirror可以都放着不影响,选取一个镜像下载比较快的放在第一个就行。比如你设置使用自己公司的私有仓库-->
<!--只有当前一个mirror无法连接的时候,才会去找后一个,类似于备份和容灾。所以当第一个mirror中不存在a.jar的时候,并不会去第二个mirror中查找,甚至于,maven根本不会去其他的mirror地址查询-->
<mirror>
<!-- 当有id为B,A,C的顺序的mirror在mirrors节点中,maven会根据字母排序来指定第一个,所以不管怎么排列,一定会找到A这个mirror来进行查找,当A无法连接,出现意外的情况下,才会去B查询-->
<id>aliyun</id>
<name>阿里云仓库地址</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<!--覆盖了Maven自带的central-->
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<!-- 全局JDK1.8配置 -->
<profile>
<id>jdk1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<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>
<!-- 阿里云配置: 提高国内的jar包下载速度 -->
<profile>
<id>aliyun-Repository</id>
<repositories>
<repository>
<id>aliyun</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>suwell-Repository</id>
<repositories>
<repository>
<id>first</id>
<name>Repository first</name>
<url>http://192.168.100.100:8181/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>gomain-Repository</id>
<repositories>
<repository>
<id>second</id>
<name>Repository second</name>
<url>http://192.168.100.100:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
激活仓库配置,拉取依赖会在这些仓库中逐个去找
<activeProfiles>
<activeProfile>jdk1.8</activeProfile>
<activeProfile>first-Repository</activeProfile>
<activeProfile>aliyun-Repository</activeProfile>
<activeProfile>second-Repository</activeProfile>
</activeProfiles>
</settings>

二、pom.xml

pom.xml 配置文件主要分为两类

  • 用于配置自己的实际依赖
  • 用于声明一些版本和仓库便于版本管理和发布。

pom配置是可以被继承的,父级依赖一般是做版本控制以及指定私有仓库的。

 

 

三、settings.xml文件

settings 主要由mirrors、servers 和profiles 三部分组成。

1、mirrors
mirrors 主要作用是一个镜像代理,便于内外网厂库切换,或者单独配置内网使用。

如果pom中的repository的id能和mirrorOf的值关联上,那么url以mirror的为准,否则以repository中自己的url为准。

<mirror>
<id>test-nexus</id>
<mirrorOf>*</mirrorOf>
<name>sugon local repository</name>
<url>http://172.22.5.34:9996/repository/sugoncloud-public/</url>
</mirror>

mirrorof 有三种值:

  • *代表 所有仓库请求都走这个配置的镜像代理
  • central 默认是maven 的仓库

2、servers

<server>
<id>nexus-releases</id>
<username>deployment</username>
<password>deployment123</password>
</server>

它关联pom中配置的私有仓库id, 在推送依赖包的时候根据id进行认证。

3、profiles
配置全局私用仓库。

注意:
如果只配置mirrors 是不能拉取父pom文件的,如果需要拉取父pom文件那么需要配置repository。

参考文章:
[1] Maven私有仓库nexus配置
[2] Java Maven settings.xml中私有仓库配置详解

标签:xml,http,Repository,私有,配置,仓库,Maven,nexus,pom
From: https://www.cnblogs.com/forestwolf/p/17622737.html

相关文章

  • NextJS - 使用 next-auth 配置 JWT token
    Nextjs中有很多身份验证选项,例如Supabase、Firebase、Userbase等等。我们将重点关注NextAuth.js以及通过凭证提供程序在现有Django后端和Next.js之间实现JWT会话的打字稿。我们将尽力专注于我们的用例以节省时间,因此我们将省略所有未使用的选项和功能。为什么选择N......
  • Sinopia 搭建npm 私有仓库
    sinopia是一个零配置的私有的带缓存功能的npm包管理工具,使用sinopia,你不用安装CouchDB或MYSQL之类的数据库,Sinopia有自己的迷你数据库,如果要下载的包不存在,它将自动去你配置的npm地址上去下载,而且硬盘中只缓存你现在过的包,以节省空间。优点不同步拉取npm库,占据大量硬盘,没有硬盘被撑......
  • JAVA | 如何安装JDK并配置
    安装JDK首先去Oracle官网。(网址随时会变,自行百度其官网就可以)点击产品->java。点击DownloadJavanow.我们可以下载JDK20、JDK17、下面还可以下载JDK8和JDK11.我们点击自己对应的操作系统下载,下载的时候需要一个Oracle账户,自己注册一下即可。下载完毕:双击安装:下一步。......
  • keepalived安装及配置文件详解
    一、安装Keepalived服务两种安装方式:(1)yum方式安装yum-yinstallkeepalived#查看安装路径rpm-qlkeepalived(2)源码安装1)安装依赖yum-yinstallgccopenssl-devellibnfnetlink-devel2)下载源码wgethttps://www.keepalived.org/software/keepalived-1.4.5.tar.......
  • 使用Spring Cloud Config实现分布式系统的配置管理
    在分布式系统中,配置管理是一个重要的议题,不同的服务可能需要不同的配置参数,而这些配置参数可能会随时发生变化。SpringCloudConfig是一个用于集中式配置管理的工具,它可以帮助开发人员轻松地管理和更新分布式系统中的配置信息。本文将深入探讨如何使用SpringCloudConfig进行配置......
  • 使用Spring Cloud Config实现微服务配置中心
    在微服务架构中,管理和维护各个微服务的配置信息变得非常重要,特别是在不同环境中(如开发、测试、生产)进行配置的时候。SpringCloudConfig是一个用于集中管理分布式系统配置的解决方案,本文将深入探讨如何使用SpringCloudConfig构建微服务配置中心,并提供代码示例。什么是微服务配置......
  • 国标GB28181视频平台LntonGBS(源码版)国标平台新增拉流超时配置的具体操作流程
    LntonGBS是一款基于公安部推出的安防主流协议(国标GB28181协议)的视频接入、处理及分发平台。它提供了一系列功能,包括视频直播监控、云端录像、云存储、检索回放、智能告警、语音对讲和平台级联等。通过支持国标GB28181协议,LntonGBS能够实现与各种符合该协议的视频设备的连接和交互。......
  • Python处理Nginx配置的实现方法
    Nginx是一个高性能的Web服务器和反向代理服务器,它可以用于实现多种功能。在实际应用中,我们可能需要根据不同的需求修改Nginx的配置文件。本文将介绍如何使用Python来处理Nginx配置文件。一、安装必要的库为了方便地操作Nginx配置文件,我们需要安装一些Python库。其中,pyparsing和ngin......
  • Nginx配置防盗链(详细了解如何配置nginx防盗链)
     worker_processes1;#允许进程数量,建议设置为cpu核心数或者auto自动检测,注意Windows服务器上虽然可以启动多个processes,但是实际只会用其中一个events{#单个进程最大连接数(最大连接数=连接数*进程数)#根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到100......
  • 申请阿里云免费SSL证书并配置https访问实战
                  文章转载:https://hashnode.blog.csdn.net/article/details/124555303......