惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
Y
Y Combinator Blog
美团技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
S
SegmentFault 最新的问题
IT之家
IT之家
Recent Announcements
Recent Announcements
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
T
The Blog of Author Tim Ferriss
Martin Fowler
Martin Fowler
Microsoft Azure Blog
Microsoft Azure Blog
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
WordPress大学
WordPress大学
博客园 - Franky
L
LangChain Blog
人人都是产品经理
人人都是产品经理
小众软件
小众软件
博客园 - 叶小钗
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
大猫的无限游戏
大猫的无限游戏
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
雷峰网
雷峰网
腾讯CDC
Google DeepMind News
Google DeepMind News
博客园 - 三生石上(FineUI控件)
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Help Net Security
Help Net Security
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News and Events Feed by Topic
V2EX - 技术
V2EX - 技术
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Schneier on Security
Schneier on Security
博客园 - 聂微东
A
Arctic Wolf
H
Heimdal Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
The Exploit Database - CXSecurity.com
C
Cyber Attacks, Cyber Crime and Cyber Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Google DeepMind News
Google DeepMind News

二丫讲梵

学习周刊-总第258期-2026年第15周 学习周刊-总第257期-2026年第14周 学习周刊-总第256期-2026年第13周 学习周刊-总第255期-2026年第12周 学习周刊-总第254期-2026年第11周 学习周刊-总第253期-2026年第10周 临时插播一条羊毛,免费领取450元大模型API代金券 学习周刊-总第252期-2026年第09周 学习周刊-总第251期-2026年第08周 学习周刊-总第250期-2026年第07周 学习周刊-总第249期-2026年第06周 诚邀评论,聊聊你所知欲知的我 学习周刊-总第248期-2026年第05周 我的QQ动态之2015年 我的QQ动态之2014年 我的QQ动态之2013年 我的QQ动态之2012年 我的QQ动态-2010-2011年 我的QQ动态-创栏小叙 学习周刊-总第247期-2026年第04周 Nexus社区版权益阉割--一文告诉你有哪些版本可以选择 学习周刊-总第246期-2026年第03周 学习周刊-总第245期-2026年第02周 学习周刊-总第244期-2026年第01周 学习周刊-总第243期-2025年第52周 学习周刊-总第242期-2025年第51周 开源项目ZenOps:带你领略禅意运维 学习周刊-总第241期-2025年第50周 用京东金融,享负债人生 学习周刊-总第240期-2025年第49周 学习周刊-总第239期-2025年第48周 整理我在静态服务透明代理上的极致求索之路,最后一个你绝想不到 学习周刊-总第238期-2025年第47周 我们输了,但收获颇多 太多了,太多了 学习周刊-总第237期-2025年第46周 学习周刊-总第236期-2025年第45周 学习周刊-总第235期-2025年第44周 二五年国庆二三事 学习周刊-总第234期-2025年第43周 学习周刊-总第233期-2025年第42周 学习周刊-总第232期-2025年第41周 学习周刊-总第231期-2025年第40周 学习周刊-总第230期-2025年第39周 西湖毅行 2025年开源世界逸闻三则 学习周刊-总第229期-2025年第38周 手抄《与妻书》 CNB开发与构建基于docker-cache缓存复用的配置实践心得 学习周刊-总第228期-2025年第37周 父亲善行录 学习周刊-总第227期-2025年第36周 带你认识我之看看我的高中同学录(其二) 学习周刊-总第226期-2025年第35周 带你认识我之看看我的高中同学录(其一) 认识神级MCP工具系列--用anyquery和数据库交互 学习周刊-总第225期-2025年第34周 学习周刊-总第224期-2025年第33周 学习周刊-总第223期-2025年第32周 学习周刊-总第222期-2025年第31周 学习周刊-总第221期-2025年第30周 CNB云原生开发环境届的瑞士军刀,详解qifei项目 vuepress-vdoing主题配置自建不蒜子统计 学习周刊-总第220期-2025年第29周 写在博客发表文章1000篇的节点 从claude cli的体验聊聊最大的敌人是我们自己的成见 学习周刊-总第219期-2025年第28周 学习周刊-总第218期-2025年第27周 学习周刊-总第217期-2025年第26周 理论正确,事实错误 学习周刊-总第216期-2025年第25周 学习周刊-总第215期-2025年第24周 学习周刊-总第214期-2025年第23周 学习周刊-总第213期-2025年第22周 学习周刊-总第212期-2025年第21周 从赵心童世锦赛夺冠聊聊我的斯诺克情缘 学习周刊-总第211期-2025年第20周 记录二五年五一之短暂回归家庭 学习周刊-总第210期-2025年第19周 学习周刊-总第209期-2025年第18周 学习周刊-总第208期-2025年第17周 Go开发实践之Gin框架将前端的dist目录embed到二进制 学习周刊-总第207期-2025年第16周 近期关于cobra库的一些实践心得总结 学习周刊-总第206期-2025年第15周 我的嗜好--嗑瓜子 记大宝参加幼儿园组织的清明烈士陵园扫墓活动 学习周刊-总第205期-2025年第14周 学习周刊-总第204期-2025年第13周 前端开发小笔记--在数组中给字段添加值与删除字段的操作 学习周刊-总第203期-2025年第12周 人生实苦,何以自渡 学习周刊-总第202期-2025年第11周 近期发现的一些优秀的工具提名(一) 学习周刊-总第201期-2025年第10周 学习周刊-总第200期-2025年第09周 记一次女友喝醉使我忍术破功 爱情风波--一次分手又复合的经历 学习周刊-总第199期-2025年第08周 整理我的信息源
将maven本地包上传到nexus私服的实践
二丫讲梵 · 2022-09-21 · via 二丫讲梵

如何配置 nexus 私服,这个问题很早之前就已经研究过,博客也发表过此文章: 使用 nexus3 配置 maven 私有仓库 (opens new window) ,本文来介绍当我们私服配置完毕之后,如何将本地开发的依赖包,上传到 nexus 私服中。

这个跟 Python 私服有点类似:

其实用一句话来表述,就是 通过私服拉包的时候,走 group 的代理,从本地上传包的时候,要走 local 的仓库。 但 maven 在 local 仓库的基础上,又开拓出了两个子概念,releasessnapshots,简单讲就是,开发过程中用到的包,未达到稳定状态时,那么这个包应该放到 snapshots 当中,已经达到稳定生产可用状态的包,应该放到 releases 中,这两个区别不大,只是一个逻辑分组,下文会讲解到。

接下来就记录一下配置方法并用测试包来验证下。

创建私服的过程这里不详述了,已知现有 maven 私仓,物料信息如下:

  • group:http://localhost:8931/repository/maven-public/
  • local-releases:http://localhost:8931/repository/maven-releases/
  • local-snapshots:http://localhost:8931/repository/maven-snapshots/

本文将介绍一个通过本地上传的方式处理包依赖的流程。

# 1,配置连接

要想通过私服拉取或者上传依赖,首先需要在 maven 的配置文件当中将配置指向我们的私服。

$ cat 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>~/.m2/prod-repository</localRepository>
    <!-- 设置发布 jar 包时的用户名及密码 -->
    <servers>
        <server>
            <id>releases</id>
            <username>admin</username>
            <password>admin</password>
        </server>

        <server>
            <id>snapshots</id>
            <username>admin</username>
            <password>admin</password>
        </server>
    </servers>

    <!-- 设置 maven 的远程仓库为 nexus -->
    <mirrors>
        <mirror>
            <id>public</id>
            <mirrorOf>*</mirrorOf>
            <name>public</name>
            <url>http://localhost:8931/repository/maven-public/</url>
        </mirror>
        <mirror>
            <id>releases</id>
            <mirrorOf>*</mirrorOf>
            <name>maven-releases</name>
            <url>http://localhost:8931/repository/maven-releases/</url>
        </mirror>
        <mirror>
            <id>snapshots</id>
            <mirrorOf>*</mirrorOf>
            <name>Local Repository</name>
            <url>http://localhost:8931/repository/maven-snapshots/</url>
        </mirror>
    </mirrors>

    <profiles>
        <profile>
            <id>central</id>
            <repositories>
                <repository>
                    <id>nexus</id>
                    <url>http://localhost:8931/repository/maven-public/</url>
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>
                </repository>
            </repositories>
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>central</activeProfile>
    </activeProfiles>

    <pluginGroups>
        <pluginGroup>org.mortbay.jetty</pluginGroup>
        <pluginGroup>org.codehaus.cargo</pluginGroup>
    </pluginGroups>
</settings>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

这样我们在本地拉包的时候就能与私服进行交互了。

# 2,手动上传

其实在 nexus 当中,也支持直接在 web 当中上传依赖包的,这里以 jenkins-client 包来举例。

在阿里的 maven 仓库中搜索,找到 0.3.6 版本。

在阿里搜索到的结果如下:

将包下载到本地,然后来到 nexus 私服当中,上传刚刚下载好的包,并把相关信息填写完整:

然后点击上传。

接着来到仓库中,可以看到对应的包已经成功上传到了仓库当中。

# 3,命令行上传

这里分两种,一种通过 pom 文件进行上传,一种是直接将 jar 文件上传,我们先来介绍基于 pom 文件的上传方式。

# 1,pom 上传

将如下内容添加到我们的 pom 文件当中,就可以通过命令行一键将依赖上传到 nexus 仓库中。

  <distributionManagement>
    <repository>
        <id>releases</id>
        <name>Nexus ReleaseRepository</name>
        <url>http://localhost:8931/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <name>Nexus SnapshotRepository</name>
        <url>http://localhost:8931/repository/maven-snapshots/</url>
    </snapshotRepository>
  </distributionManagement>

1
2
3
4
5
6
7
8
9
10
11
12

注意其中的 id 与 settings 当中的 id 是对应的。

一个标准的 pom 上传文件内容如下,这里示例将 jenkins-client-v0.3.7 版本的包传到私服:

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

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
        <groupId>com.offbytwo.jenkins</groupId>
        <artifactId>jenkins-client</artifactId>
        <version>0.3.7</version>
    <name>jenkins-client</name>

    <distributionManagement>
        <repository>
            <id>releases</id>
            <url>http://localhost:8931/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <url>http://localhost:8931/repository/maven-snapshots/</url>
        </snapshotRepository>
      </distributionManagement>
</project>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

注意:如果 version 内容为 <version>0.3.7-SNAPSHOT</version>,则这个包将会自动传到 snapshot 分区当中,而不会传到 release 分区,反之亦然。

配置完毕之后,执行如下命令进行上传:

$ mvn -s settings.xml deploy -Dmaven.test.skip -Dmaven.install.skip
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------< com.offbytwo.jenkins:jenkins-client >-----------------
[INFO] Building jenkins-client 0.3.7
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from public: http://localhost:8931/repository/maven-public/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.pom

---中间日志省略---

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:36 min
[INFO] Finished at: 2022-09-20T15:58:53+08:00
[INFO] ------------------------------------------------------------------------

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

执行完毕之后,我们可以来到私服当中看到对应的依赖包:

申明

原创文章eryajf,未经授权,严禁转载,侵权必究!此乃文中随机水印,敬请读者谅解。

# 2,通过命令行直接传 jar

我们把 v0.3.8 的包下载到本地,然后执行如下命令进行上传:

mvn deploy:deploy-file \
    -DgroupId=com.offbytwo.jenkins \
    -DartifactId=jenkins-client \
    -Dversion=0.3.8 \
    -Dfile=/root/liql/jenkins-client-0.3.8.jar \
    -Durl=http://localhost:8931/repository/maven-releases/ \
    -DrepositoryId=releases \
    -s settings.xml

1
2
3
4
5
6
7
8

看到 BUILD SUCCESS 则说明上传成功。 来到仓库当中,也可以看到这个版本的依赖包了:

# 3,问题

我在本地执行命令行直接上传的时候,始终无法正常上传,报错如下:

[ERROR] Could not find goal 'deploy-file ' in plugin org.apache.maven.plugins:maven-deploy-plugin:2.7 among available goals deploy-file, help, deploy -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoNotFoundException

1
2
3
4
5
6
7

看到有地方说是 mvn 版本的问题,但据我测试下来,并不是版本的问题,大概可能是我电脑为 m1 版本的缘故,如上指令在 centos 上测试正常运行。