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

推荐订阅源

Engineering at Meta
Engineering at Meta
酷 壳 – CoolShell
酷 壳 – CoolShell
Forbes - Security
Forbes - Security
S
Schneier on Security
Cyberwarzone
Cyberwarzone
L
Lohrmann on Cybersecurity
NISL@THU
NISL@THU
T
Tenable Blog
Simon Willison's Weblog
Simon Willison's Weblog
G
GRAHAM CLULEY
Schneier on Security
Schneier on Security
K
Kaspersky official blog
AI
AI
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Threatpost
Attack and Defense Labs
Attack and Defense Labs
I
Intezer
The Cloudflare Blog
博客园 - 叶小钗
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Blog — PlanetScale
Blog — PlanetScale
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
IT之家
IT之家
Recent Announcements
Recent Announcements
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
aimingoo的专栏
aimingoo的专栏
The GitHub Blog
The GitHub Blog
宝玉的分享
宝玉的分享
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
O
OpenAI News
大猫的无限游戏
大猫的无限游戏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
量子位
Microsoft Security Blog
Microsoft Security Blog
B
Blog
Jina AI
Jina AI
Hugging Face - Blog
Hugging Face - Blog
D
Docker
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
美团技术团队
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
阮一峰的网络日志
阮一峰的网络日志
雷峰网
雷峰网
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

李锋镝的博客

LiteLLM 本地代理搭建 Claude-HUD 使用文档 Kratos+ —— Kratos 主题二次开发记录 译文:如何将单体应用拆解为微服务 codebase-memory-mcp 极简完整使用指南 Claude Haiku 4.5、Claude Sonnet 4.6、Claude Opus 4.7 区别以及各自的新特性 SchedulingConfigurer详解 踩坑60+次后,我终于搞懂 Claude Skill 怎么写才会真的触发 Everything Claude Code 详细使用文档 配置Jackson使用字段而不是getter/setter来序列化和反序列化 这个域名注册整整十年了,十年时间,真快啊 Claude Code全维度实战指南:从入门到精通,解锁AI编程新范式 Apollo配置中心中的protalDB的作用是什么 org.apache.ibatis.plugin.Interceptor类详细介绍及使用 岁末 Excel2016右键新建工作表,打开时提示“因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配。”的解决办法 wordpress增加说说功能 Java 为什么有这么多 “O”? 别再背线程池的七大参数了,现在面试官都这么问 2024年11月1号 农历十月初一 我的第一个WordPress插件:Dylan Custom Plugin上线了 推荐一款比较养眼的Xshell配色方案 hnswlib installation failed 开工啦~ 阳了... MybatisCodeHelperPro激活 @Async注解的坑 新买的笔记本发货啦…… 这个中秋节感觉过的好累啊 IDEA下载源码报:Cannot connect to the Maven process. Try again later. RocketMQ的push消费方式实现详解 看病难~取药难~~ 笑死、腹肌……根本不可能有腹肌的~~ 居家办公了~ C# 11 的这个新特性,我愿称之最强! IntelliJ IDEA 2020.3.x永久白嫖(Windows/Mac) IDEA无限试用方法【2020.3最新亲测有效】 SpringBoot使用注解的方式构建Elasticsearch查询语句,实现多条件的复杂查询 UUID太长怎么办?快来试试NanoId 忽然发现,在校大学生可以免费领一年有道云笔记会员~ 醒醒~补个税了 使用itext和freemarker来根据Html模板生成PDF文件,加水印、印章 来来来,用python画一个冰墩墩儿 SpringBoot整合GraphQL入门教程 办理居住证困难重重啊! 妈呀,昨天晚上睡觉做了一晚上的梦,可累死我了 感觉Typecho很简洁啊…… WordPress的自动更新好烦啊 BeanCopier工具类(性能优化工具类) 内存屏障浅析 居住证可算是申请通过了…… 试了下壁挂炉供暖 关于重阳节 居住证签注... Spring Boot 2.x使用PostgreSQL数据库 十一节后开工头一天,修了个耳机…… 玉楼春·尊前拟把归期说 nginx反向代理配置去除前缀 1931→2021! Navicat Premium数据库账号密码解密 百度的索引量数据现在有点儿太夸张了吧? 哇塞~这个小姐姐实在太惊艳了…… 关于8月29号下午博客故障的一些记录 如何形象的描述反应式编程中的背压(Backpressure)机制? 基于Java8的Either类 海琴烟~~~ JMX监控权限认证配置 IntelliJ IDEA 2019.3.3 永久激活 破解[Windows] SpringBoot整合Elasticsearch详细步骤以及代码示例(附源码) SpringBoot整合Elasticsearch游标查询(scroll) GitLab创建新项目,初次提交命令和流程 吐槽下Google浏览器~ 从零搭建Spring Cloud Gateway网关(一) 从零搭建Spring Cloud Gateway网关(二)—— 打印请求响应日志 博客有logo啦 你的答案 数据库事务的一点简单总结 Spring Boot发展史(Spring Boot介绍) 【漫画】戏说外行对程序员的误会有多深 【收藏】从面试官角度观察到的程序员技能瓶颈,同时给出突破瓶颈的建议 Git中.gitignore文件不起作用的解决办法 背影 - 朱自清 jmap命令(jdk1.8) 彻底搞懂mysql日志系统binlog,redolog,undolog 出院了~~~ linux中ftp查看不到文件列表的问题 PHP版本怎么更新啊…… 成语接龙 StarUML4.0破解文件 Java SPI详解 WordPress评论框增加自定义表情 因在公司上不正经网站,我没过试用期… 优化了MYSQL大量写入问题,老板奖励了1000块给我 不慌不忙的坚强(林徽因39段最美文字!) ConcurrentHashMap常用方法源码解析(jdk1.8) 我是如何失去团队掌控的? HBASE填坑日志 关闭apache httpclient4.5 DEBUG日志 使用OpenShift搭建k8s集群 SonarQube Scanner的配置与使用简介
解决idea中可以成功执行maven命令但是通过Terminal命令行执行失败的问题
李锋镝 · 2025-07-30 · via 李锋镝的博客

问题

通过Terminal命令行执行maven命令报错:

 mvn clean
[INFO] Scanning for projects...
[INFO] Artifact com.example:example-bom:pom:1.2.2 is present in the local repository, but cached from a remote repository ID that is unavailable in current build context, verifying that is downloadable from [central (https://repo.maven.apache.org/maven2, default, releases)]
[INFO] Artifact com.example:example-bom:pom:1.2.2 is present in the local repository, but cached from a remote repository ID that is unavailable in current build context, verifying that is downloadable from [central (https://repo.maven.apache.org/maven2, default, releases)]
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.example:example-common:1.2.3-SNAPSHOT: The following artifacts could not be resolved: com.example:example-bom:pom:1.2.2 (present, but unavailable): com.example:example-bom:pom:1.2.2 was not found in https://repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at no local POM @ line 4, column 13
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.example:example-common:1.2.3-SNAPSHOT (/Users/bjsttlp176/WorkSpace/Public/example-common/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for com.example:example-common:1.2.3-SNAPSHOT: The following artifacts could not be resolved: com.example:example-bom:pom:1.2.2 (present, but unavailable): com.example:example-bom:pom:1.2.2 was not found in https://repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at no local POM @ line 4, column 13 -> [Help 2]
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

不止是mvn clean,执行其他的maven命令也会失败,报错原因大同小异。

但是通过idea中的maven面板执行就能成功:

[INFO] Reactor Summary for example-common 1.2.3-SNAPSHOT:
[INFO] 
[INFO] example-common ...................................... SUCCESS [  0.054 s]
[INFO] example-common-constants ............................ SUCCESS [  0.001 s]
[INFO] example-common-swagger .............................. SUCCESS [  0.001 s]
[INFO] example-common-utils ................................ SUCCESS [  0.001 s]
[INFO] example-common-redis-tools .......................... SUCCESS [  0.001 s]
[INFO] redis-common-core .................................. SUCCESS [  0.001 s]
[INFO] redis-common-starter ............................... SUCCESS [  0.001 s]
[INFO] example-common-regular .............................. SUCCESS [  0.002 s]
[INFO] example-common-security ............................. SUCCESS [  0.002 s]
[INFO] example-common-web .................................. SUCCESS [  0.001 s]
[INFO] spring-common-util ................................. SUCCESS [  0.001 s]
[INFO] example-common-datasource ........................... SUCCESS [  0.002 s]
[INFO] example-common-dtp .................................. SUCCESS [  0.024 s]
[INFO] example-common-lb ................................... SUCCESS [  0.000 s]
[INFO] example-common-center-config ........................ SUCCESS [  0.001 s]
[INFO] example-apollo-config-starter ....................... SUCCESS [  0.001 s]
[INFO] example-common-trace ................................ SUCCESS [  0.001 s]
[INFO] web-common-config .................................. SUCCESS [  0.001 s]
[INFO] example-common-http ................................. SUCCESS [  0.002 s]
[INFO] example-common-mq ................................... SUCCESS [  0.000 s]
[INFO] kafka-swim-line .................................... SUCCESS [  0.001 s]
[INFO] example-kafka-starter ............................... SUCCESS [  0.001 s]
[INFO] example-common-mybatis .............................. SUCCESS [  0.001 s]
[INFO] example-rocketmq-starter ............................ SUCCESS [  0.003 s]
[INFO] kafka-swim-line-2.8.x .............................. SUCCESS [  0.001 s]
[INFO] example-common-auth ................................. SUCCESS [  0.001 s]
[INFO] example-auth-client ................................. SUCCESS [  0.001 s]
[INFO] example-common-transport ............................ SUCCESS [  0.001 s]
[INFO] example-transport-auth .............................. SUCCESS [  0.002 s]
[INFO] example-transport-auth-client-starter ............... SUCCESS [  0.002 s]
[INFO] example-transport-auth-client-javax-starter ......... SUCCESS [  0.001 s]
[INFO] example-collect ..................................... SUCCESS [  0.002 s]
[INFO] context-collect-javax .............................. SUCCESS [  0.002 s]
[INFO] example-transport-starter ........................... SUCCESS [  0.001 s]
[INFO] example-transport-javax-starter ..................... SUCCESS [  0.002 s]
[INFO] example-transport-jakarta-starter ................... SUCCESS [  0.001 s]
[INFO] example-common-log .................................. SUCCESS [  0.001 s]
[INFO] example-common-sentinel ............................. SUCCESS [  0.001 s]
[INFO] sentinel-common-core ............................... SUCCESS [  0.001 s]
[INFO] sentinel-app-starter ............................... SUCCESS [  0.001 s]
[INFO] sentinel-gateway-starter ........................... SUCCESS [  0.000 s]
[INFO] example-common-job .................................. SUCCESS [  0.001 s]
[INFO] example-auth-client-starter ......................... SUCCESS [  0.001 s]
[INFO] example-auth-client-javax-starter ................... SUCCESS [  0.001 s]
[INFO] example-common-liquibase ............................ SUCCESS [  0.001 s]
[INFO] web-common-util .................................... SUCCESS [  0.002 s]
[INFO] example-common-graceful-shutdown .................... SUCCESS [  0.001 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.400 s
[INFO] Finished at: 2025-07-23T15:33:32+08:00
[INFO] ------------------------------------------------------------------------

问题排查

一开始以为是maven版本不一致导致的。

IDEA 使用的是内置 Maven 3.9.9(路径:/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3)

系统环境使用的是 Homebrew 安装的 Maven 3.9.9(路径:/opt/homebrew/Cellar/maven/3.9.9/libexec)

虽然版本号相同,但路径不同可能导致配置冲突。

所以修改了idea的maven路径,和系统环境的一致,结果问题依旧。

后来通过比较idea的maven命令参数,发现其实idea执行maven命令的时候,通过命令行参数(-s)指定了项目的配置文件,这个配置文件中的仓库地址是私服的仓库地址。

而系统环境执行maven则使用的是maven默认的配置文件,导致Maven 在本地仓库中找到了依赖包,但由于某些原因无法验证其有效性,因此尝试从中央仓库重新下载。然而中央仓库并没有我自己的依赖包,导致下载失败。

通过Terminal命令行加-s参数的方式也验证了这个问题:

 mvn clean -s /WorkSoft/maven/common/settings.xml

解决办法

解决办法有两种,一种是使用-s指定配置文件,不过这样太麻烦,每次执行命令都需要加;第二个办法就是修改Maven的默认配置文件。

下面说几个修改maven配置文件的办法:

Maven 默认配置文件的设置方法

Maven 支持两种配置文件,并且会按照特定的优先级加载它们。要设置默认配置文件而不使用 -s 参数,可以通过以下方式实现:

1. 全局配置文件(System-wide Settings)

Maven 会自动读取其安装目录下的 conf/settings.xml 文件:

${MAVEN_HOME}/conf/settings.xml

优点:所有项目默认使用此配置,无需额外配置。
缺点:修改需要管理员权限,不适合多环境切换。

2. 用户配置文件(User-specific Settings)

Maven 会自动读取用户主目录下的 settings.xml 文件:

${user.home}/.m2/settings.xml

配置步骤

  1. 在用户主目录下创建 .m2 文件夹(如果不存在):
    mkdir -p ~/.m2
  2. .m2 目录下创建或编辑 settings.xml 文件:
    touch ~/.m2/settings.xml
  3. 添加你的配置(如镜像、仓库、认证等):
    <settings>
    <mirrors>
        <mirror>
            <id>private-repo</id>
            <mirrorOf>*</mirrorOf>
            <url>http://your-private-repo.com/repository/maven-public/</url>
        </mirror>
    </mirrors>
    </settings>

3. 环境变量配置(高级方法)

通过设置 MAVEN_OPTSMAVEN_SKIP_RC 环境变量,可以覆盖默认行为:

方法 1:设置 MAVEN_OPTS

在 shell 配置文件(如 ~/.bashrc~/.zshrc)中添加:

export MAVEN_OPTS="-s /path/to/your/settings.xml"

效果:所有 Maven 命令都会自动使用指定的配置文件。

方法 2:使用 mavenrc 文件
  1. 在用户主目录下创建 .mavenrc 文件:
    touch ~/.mavenrc
  2. 添加以下内容:
    MAVEN_SKIP_RC=true  # 跳过默认配置
    MAVEN_OPTS="-s /path/to/your/settings.xml"

4. IDE 中的配置

在 IntelliJ IDEA 中设置默认配置文件:

  1. 打开 File > Settings > Build, Execution, Deployment > Build Tools > Maven
  2. User settings file 字段中指定路径(如 ~/.m2/settings.xml)。
  3. 勾选 Override 选项,确保 IDEA 使用此配置。

优先级顺序

Maven 加载配置的优先级从高到低为:

  1. 命令行参数 -s /path/to/settings.xml
  2. MAVEN_OPTS 环境变量中指定的 -s 参数
  3. 用户主目录下的 ~/.m2/settings.xml
  4. Maven 安装目录下的 ${MAVEN_HOME}/conf/settings.xml

验证方法

使用以下命令查看 Maven 实际使用的配置:

mvn help:effective-settings

输出会显示当前生效的配置文件路径和内容。

注意事项

  • 如果同时存在全局和用户配置文件,Maven 会合并它们,用户配置优先级更高。
  • 修改配置后,可能需要重启 IDE 或终端会话才能生效。
  • 对于企业环境,推荐使用用户配置文件,避免修改全局配置。
除非注明,否则均为李锋镝的博客原创文章,转载必须以链接形式标明本文链接

本文链接:https://www.lifengdi.com/dai-ma-ren-sheng/4493