Maven插件需绑定到default生命周期阶段才能自动执行,否则静默存在;可通过help:describe确认默认绑定,或在pom.xml中用executions手动绑定phase和goal,且phase必须拼写正确。

要让Maven插件在构建过程中自动执行,必须将其目标(goal)明确绑定到default生命周期的某个阶段,否则插件只会静默存在、不会触发。
确认插件是否已默认绑定
执行 mvn help:describe -Dplugin=compiler 查看 maven-compiler-plugin 的绑定信息,重点关注 “Goal prefix” 和 “Lifecycle phase” 字段;若显示 “compile → compile”,说明该插件的 compile 目标已默认绑定到 default 生命周期的 compile 阶段。
不是所有插件都自带绑定——比如 maven-antrun-plugin 默认不绑定任何阶段,调用 mvn antrun:run 才会执行,但不会随 mvn compile 自动触发。
手动绑定插件目标到指定阶段
在 pom.xml 的 <build><plugins></plugins></build> 区域内添加插件配置,并显式指定 <executions></executions> 和 <phase></phase>:
① 在 <plugin></plugin> 标签下嵌套 <executions></executions>;
② 在 <executions></executions> 内添加 <execution></execution> 块;
Java Maven 项目审查工作流的通用输入处理。当 Java Maven 项目以 ZIP压缩包或 GitLab 仓库 URL 形式提供且需要...时使用。
③ 为该 <execution></execution> 设置唯一 <id></id>(如 add-banner),并指定 <phase></phase>(例如 process-resources);
④ 在 <goals></goals> 中声明要执行的目标(如 <goal>run</goal>);
【phase 值必须是 default 生命周期中真实存在的阶段名】,拼写错误(如写成 precess-resources)会导致构建跳过该 execution,且无报错提示。
覆盖默认绑定(可选)
方法一:使用相同 <phase></phase> + 更高优先级的 <execution></execution> —— Maven 按 <executions></executions> 中声明顺序执行同阶段的多个 execution;
方法二:禁用原绑定,再重新绑定 —— 在插件配置中添加 <configuration><skip>true</skip></configuration>(仅适用于支持 skip 参数的插件,如 maven-surefire-plugin);
方法三:通过 mvn -Dmaven.test.skip=true 临时跳过 test 阶段绑定的插件,但不修改 pom。

















