Apache Maven
$ mvn 基金会 中风险Apache Maven(mvn)基于 pom.xml 编排 Java/JVM 编译、依赖解析、打包与插件目标执行。它支持 -B(--batch-mode)、--color never 与 -o(--offline),但构建日志为冗长的纯文本且缺少原生 --json 输出。
brew install maven mvn 直接在本地编译 JVM 字节码、解析 ~/.m2 制品并运行 Surefire/Failsafe 测试套件,MCP 无法替代本地构建执行。
Agent 友好度体检单
本地探针实测证据抓取的 --help 摘要
usage: mvn [options] [<goal(s)>] [<phase(s)>]
Options:
-am,--also-make If project list is specified,
also build projects required by
the list
-amd,--also-make-dependents If project list is specified,
also build projects that depend
on projects on the list
-B,--batch-mode Run in non-interactive (batch)
mode (disables output color)
-b,--builder <arg> The id of the build strategy to
use
-C,--strict-checksums Fail the build if checksums don't
match
-c,--lax-checksums Warn if checksums don't match
--color <arg> Defines the color mode of the
output. Supported are 'auto',
'always', 'never'.
-cpu,--check-plugin-updates Ineffective, only kept for
backward compatibility
-D,--define <arg> Define a user property
-e,--errors Produce execution error messages
-emp,--encrypt-master-password <arg> Encrypt master security password
-ep,--encrypt-password <arg> Encrypt server password
-f,--file <arg> Force the use of an alternate POM
file (or directory with pom.xml)
-fae,--fail-at-end Only fail the build afterwards;
allow all non-impacted builds to
continue
-ff,--fail-fast Stop at first failure in
reactorized builds
-fn,--fail-never NEVER fail the build, regardless
of project result
-gs,--global-settings <arg> Alternate path for the global
settings file
-gt,--global-toolchains <arg> Alternate path for the global
toolchains file
-h,--help Display help information
-itr,--ignore-transitive-repositories If set, Mav FCRS-1.0 六维评分拆解
支持 -B(--batch-mode)、-q、--color never 与 -o(--offline),但输出为非结构化长文本且缺少 --json 与全局 --dry-run。
-B --color neversuppresses prompts and ANSI escapes- No native
--jsonoutput across lifecycle goals
构建产物隔离在 target/ 与 ~/.m2/repository,但 mvn 缺少空跑模式且 deploy 会向远程仓库推送制品。
-ooffline mode prevents unexpected network resolution- No global
--dry-runbefore running lifecycle plugins
可通过 Homebrew、SDKMAN 与 ./mvnw wrapper 在 macOS、Linux 与 Windows 运行,依赖宿主 JDK。
- Requires compatible JDK installed on host
JVM 生态的标准化构建生命周期,但冷启动开销和海量 [INFO] 日志容易消耗上下文窗口。
- Universal Java build lifecycle; slower incremental builds than Gradle/mvnd
Apache 软件基金会旗舰项目(apache/maven),采用 Apache-2.0 协议。
- Official Apache Software Foundation repository
maven.apache.org 提供全面官方文档,但各插件参数分散在独立插件页面。
- Official CLI reference at maven.apache.org
安全边界、鉴权与放权指南
访问公共 Maven Central 无需认证;私有仓库凭据与 GPG 密钥配置在 ~/.m2/settings.xml 中。
Apache-2.0 开源 CLI,免费使用。
# Apache Maven (mvn) Agent Rules - Always pass `-B --color never` (and `-q` or `-fae` where appropriate) to avoid prompts and log bloat. - Prefer `./mvnw` if present in the repo, and never run `mvn deploy` without explicit user approval.
Agent 高频安全命令配方
只读查询(安全推荐)
mvn -B --color never help:effective-pom
展开父 POM、profiles 与属性,查看最终生效的构建配置。
mvn -B --color never dependency:tree
在不运行编译或测试阶段的前提下输出 Maven 传递依赖树。
受控写入与预演
mvn -B -q --color never test
非交互编译并执行单元测试,同时抑制冗长的 [INFO] 进度日志。
核心优势
- +
-B(--batch-mode)与--color never确保无交互、无 ANSI 转义输出。 - +
mvn -q可裁剪大量[INFO]日志,仅保留精简的错误诊断信息。 - +
dependency:tree与help:effective-pom可清晰透视传递依赖与最终配置。
注意事项与踩坑点
- ! 不支持原生
--json输出或全局--dry-run选项。 - ! 若不使用
-q或过滤,冗长的生命周期日志会迅速撑爆 Agent 上下文。