Rpm-maven-plugin 最佳实践
# 报错情况
modules/ambari, assemblyPhase=package, sun.cpu.endian=little, args.mkdir=, java.vm.version=25.202-b08, parsedVersion.incrementalVersion=0, java.class.path=/opt/modules/apache-maven-3.8.4/boot/plexus-classworlds-2.6.0.jar, dirsep=/, os.arch=amd64, ambariVersion=2.8.0.0, executable.brunch=brunch, maven.build.version=Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537), executable.shell=sh, sun.java.launcher=SUN_STANDARD, guice.version=4.1.0, deb.publisher=Hortonworks, java.vm.specification.vendor=Oracle Corporation, file.separator=/, java.runtime.version=1.8.0_202-b08, sun.boot.class.path=/opt/modules/jdk1.8.0_202/jre/lib/resources.jar:/opt/modules/jdk1.8.0_202/jre/lib/rt.jar:/opt/modules/jdk1.8.0_202/jre/lib/sunrsasign.jar:/opt/modules/jdk1.8.0_202/jre/lib/jsse.jar:/opt/modules/jdk1.8.0_202/jre/lib/jce.jar:/opt/modules/jdk1.8.0_202/jre/lib/charsets.jar:/opt/modules/jdk1.8.0_202/jre/lib/jfr.jar:/opt/modules/jdk1.8.0_202/jre/classes, organization.logo=https://www.apache.org/images/asf_logo_wide.gif, env.XDG_RUNTIME_DIR=/run/user/0, fasterxml.jackson.databind.version=2.12.7.1, maven.version=3.8.4, user.country=US, executable.mkdir=mkdir, checkstyle.version=8.9, env.SHELL=/bin/bash, maven.home=/opt/modules/apache-maven-3.8.4, maven.compiler.target=1.7, nodemodules.dir=node_modules, eclipselink.version=2.6.2, executable.rmdir=rm, java.vendor=Oracle Corporation, maven.compiler.source=1.7, java.specification.version=1.8, sun.arch.data.model=64}
[INFO] Creating spec file /opt/modules/ambari/ambari-web/target/rpm/ambari-web/SPECS/ambari-web.spec
[DEBUG] About to execute '/bin/sh -c cd /opt/modules/ambari/ambari-web/target/rpm/ambari-web/SPECS && rpmbuild -bb --buildroot /opt/modules/ambari/ambari-web/target/rpm/ambari-web/buildroot --define '_topdir /opt/modules/ambari/ambari-web/target/rpm/ambari-web' --target noarch-redhat-linux ambari-web.spec'
[INFO] Building target platforms: noarch-redhat-linux
[INFO] Building for target noarch-redhat-linux
[INFO] Processing files: ambari-web-2.8.0.0-0.noarch
[INFO] Checking for unpackaged file(s): /usr/lib/rpm/check-files /opt/modules/ambari/ambari-web/target/rpm/ambari-web/buildroot
[INFO] Wrote: /opt/modules/ambari/ambari-web/target/rpm/ambari-web/RPMS/noarch/ambari-web-2.8.0.0-0.noarch.rpm
[INFO] Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.MIUgbh
[WARNING] + umask 022
[WARNING] + cd /opt/modules/ambari/ambari-web/target/rpm/ambari-web/BUILD
[WARNING] + /usr/bin/rm -rf /opt/modules/ambari/ambari-web/target/rpm/ambari-web/buildroot
[WARNING] + exit 0
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Ambari Web 2.8.0.0.0:
[INFO]
[INFO] Ambari Web ......................................... SUCCESS [20:52 min]
[INFO] Ambari Views ....................................... SUCCESS [ 3.706 s]
[INFO] Ambari Admin View .................................. SUCCESS [ 39.368 s]
[INFO] ambari-utility ..................................... SUCCESS [ 3.818 s]
[INFO] Ambari Server SPI .................................. SUCCESS [ 0.875 s]
[INFO] Ambari Service Advisor ............................. SUCCESS [ 3.460 s]
[INFO] Ambari Server ...................................... FAILURE [06:29 min]
[INFO] Ambari Functional Tests ............................ SKIPPED
[INFO] Ambari Agent ....................................... FAILURE [ 14.595 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20:52 min (Wall Clock)
[INFO] Finished at: 2025-05-25T11:14:27+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (generate-hash-files) on project ambari-agent: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (generate-hash-files) on project ambari-agent: Command execution failed.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:196)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:186)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
at java.lang.Thread.run (Thread.java:748)
Caused by: org.apache.maven.plugin.MojoExecutionException: Command execution failed.
at org.codehaus.mojo.exec.ExecMojo.execute (ExecMojo.java:362)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:196)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:186)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
at java.lang.Thread.run (Thread.java:748)
Caused by: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:377)
at org.apache.commons.exec.DefaultExecutor.execute (DefaultExecutor.java:160)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:610)
at org.codehaus.mojo.exec.ExecMojo.execute (ExecMojo.java:352)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:196)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:186)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
at java.lang.Thread.run (Thread.java:748)
[ERROR] Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.1.4:rpm (default-cli) on project ambari-server: RPM build execution returned: '1' executing '/bin/sh -c cd '/opt/modules/ambari/ambari-server/target/rpm/ambari-server/SPECS' && 'rpmbuild' '-bb' '--target' 'x86_64-redhat-linux' '--buildroot' '/opt/modules/ambari/ambari-server/target/rpm/ambari-server/buildroot' '--define' '_topdir /opt/modules/ambari/ambari-server/target/rpm/ambari-server' '--define' '_build_name_fmt %%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm' '--define' '_builddir %{_topdir}/BUILD' '--define' '_rpmdir %{_topdir}/RPMS' '--define' '_sourcedir %{_topdir}/SOURCES' '--define' '_specdir %{_topdir}/SPECS' '--define' '_srcrpmdir %{_topdir}/SRPMS' 'ambari-server.spec'' -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.1.4:rpm (default-cli) on project ambari-server: RPM build execution returned: '1' executing '/bin/sh -c cd '/opt/modules/ambari/ambari-server/target/rpm/ambari-server/SPECS' && 'rpmbuild' '-bb' '--target' 'x86_64-redhat-linux' '--buildroot' '/opt/modules/ambari/ambari-server/target/rpm/ambari-server/buildroot' '--define' '_topdir /opt/modules/ambari/ambari-server/target/rpm/ambari-server' '--define' '_build_name_fmt %%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm' '--define' '_builddir %{_topdir}/BUILD' '--define' '_rpmdir %{_topdir}/RPMS' '--define' '_sourcedir %{_topdir}/SOURCES' '--define' '_specdir %{_topdir}/SPECS' '--define' '_srcrpmdir %{_topdir}/SRPMS' 'ambari-server.spec''
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:196)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:186)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
at java.lang.Thread.run (Thread.java:748)
Caused by: org.apache.maven.plugin.MojoExecutionException: RPM build execution returned: '1' executing '/bin/sh -c cd '/opt/modules/ambari/ambari-server/target/rpm/ambari-server/SPECS' && 'rpmbuild' '-bb' '--target' 'x86_64-redhat-linux' '--buildroot' '/opt/modules/ambari/ambari-server/target/rpm/ambari-server/buildroot' '--define' '_topdir /opt/modules/ambari/ambari-server/target/rpm/ambari-server' '--define' '_build_name_fmt %%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm' '--define' '_builddir %{_topdir}/BUILD' '--define' '_rpmdir %{_topdir}/RPMS' '--define' '_sourcedir %{_topdir}/SOURCES' '--define' '_specdir %{_topdir}/SPECS' '--define' '_srcrpmdir %{_topdir}/SRPMS' 'ambari-server.spec''
at org.codehaus.mojo.rpm.RPMHelper.buildPackage (RPMHelper.java:169)
at org.codehaus.mojo.rpm.AbstractRPMMojo.execute (AbstractRPMMojo.java:706)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:196)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call (MultiThreadedBuilder.java:186)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
at java.lang.Thread.run (Thread.java:748)
[ERROR]
[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/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <args> -rf :ambari-agent
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# 问题背景
在 Ambari 源码编译及打包 rpm 阶段,前端依赖(Node.js/Yarn)通常能顺利构建,但到了 ambari-agent
或 ambari-server
阶段,经常会由于 rpm-maven-plugin 的默认依赖检测、shebang 校验、以及各种包后处理逻辑过严,导致如下典型报错:
警告
[ERROR] Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.1.4:rpm (default-cli) on project ambari-server: RPM build execution returned: '1'
Reactor Summary 中表现为 Web、Views 等模块 SUCCESS,Agent、Server FAILURE,根因就是 rpm 打包流程未做兼容性屏蔽。
# 解决办法(最佳实践)
直接在 ambari-agent 的 pom.xml(server 同理)rpm-maven-plugin 配置段内, 增加 defineStatements 屏蔽依赖检测和多余后处理,即可一劳永逸解决该问题。
# 推荐配置片段如下:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1.4</version>
<configuration>
<!-- ...已有配置... -->
<requires>
<require>${rpm.dependency.list}</require>
</requires>
<defineStatements>
<!-- 屏蔽依赖分析,防止 requires/provides 误报 -->
<defineStatement>__requires_exclude .*</defineStatement>
<defineStatement>__provides_exclude .*</defineStatement>
<!-- 禁止生成 debuginfo 包,避免冗余 rpm -->
<defineStatement>debug_package %{nil}</defineStatement>
<!-- 禁止 rpm 安装后自动脚本、jar repack -->
<defineStatement>__os_install_post %{nil}</defineStatement>
<defineStatement>__jar_repack %{nil}</defineStatement>
<defineStatement>__spec_install_post %{nil}</defineStatement>
</defineStatements>
<!-- ...已有配置... -->
</configuration>
</plugin>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
提示
这一段配置的核心意义:
- 依赖检测兜底 避免所有 rpm-maven-plugin 自动依赖分析导致的构建失败。
- 不再生成 debug 包 节省空间,避免多余产物。
- 后处理安全兜底 各类历史脚本、模板文件误判问题一次性消除。
# 实操效果
加上这段配置后,你会发现之前如 RPM build execution returned: '1'
的致命报错基本消失。即使有其它小问题,也不会再被
rpm-maven-plugin 的过度检测卡住主流程。
# 补充说明与手动验证
我们可以提取出 rpm-maven-plugin 最终执行的 rpm build 命令,做手动调试:
警告
mvn clean 后这个ambari-server.spec
文件是没有的。
cd /opt/modules/ambari/ambari-server/target/rpm/ambari-server/SPECS
rpmbuild -bb \
--target x86_64-redhat-linux \
--buildroot /opt/modules/ambari/ambari-server/target/rpm/ambari-server/buildroot \
--define "_topdir /opt/modules/ambari/ambari-server/target/rpm/ambari-server" \
--define "_build_name_fmt %%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
--define "_builddir %{_topdir}/BUILD" \
--define "_rpmdir %{_topdir}/RPMS" \
--define "_sourcedir %{_topdir}/SOURCES" \
--define "_specdir %{_topdir}/SPECS" \
--define "_srcrpmdir %{_topdir}/SRPMS" \
ambari-server.spec
2
3
4
5
6
7
8
9
10
11
12
13
笔记
如果还遇到 shebang 相关报错,可批量替换脚本首行为 #!/usr/bin/env python2
或 python3
,或直接配合 defineStatements
做兜底屏蔽。