温馨提示 此內容版本在
ttr-2.2.1已經修復,低於該版本需要手動處理。有任何問題可以聯繫作者,或者訪問 TTBigdata知識庫 獲取其他技術支持。
一、問題背景
在編譯 Ambari Views 模塊時,常會遇到以下錯誤:
典型報錯信息如下:
[DEBUG] (f) session = org.apache.maven.execution.MavenSession@518cf84a
[DEBUG] (s) silent = false
[DEBUG] (s) skip = false
[DEBUG] (f) stripClassifier = false
[DEBUG] (s) stripVersion = false
[DEBUG] (f) useBaseVersion = true
[DEBUG] (s) useRepositoryLayout = false
[DEBUG] (s) useSubDirectoryPerArtifact = false
[DEBUG] (s) useSubDirectoryPerScope = false
[DEBUG] (s) useSubDirectoryPerType = false
[DEBUG] -- end configuration --
[INFO] Copying classes to /opt/modules/ambari3/contrib/views/files/target/lib/ambari-views-utils-3.0.0.0.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Ambari Contrib Views 3.0.0.0.0:
[INFO]
[INFO] Ambari Contrib Views ............................... SUCCESS [ 4.940 s]
[INFO] Ambari View Utils .................................. SUCCESS [ 29.083 s]
[INFO] Ambari View Commons ................................ SUCCESS [ 18.491 s]
[INFO] Files .............................................. FAILURE [ 48.178 s]
[INFO] Capacity Scheduler ................................. SKIPPED
[INFO] Ambari Views Package ............................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:40 min
[INFO] Finished at: 2025-10-24T06:44:06Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.1.1:copy-dependencies (default) on project files: Artifact has not been packaged yet. When used on reactor artifact, copy shou
ld be executed after packaging: see MDEP-187. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.1.1:copy-dependencies (default) on project files: Artifact has not been packag
ed yet. When used on reactor artifact, copy should be executed after packaging: see MDEP-187.
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.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:569)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: Artifact has not been packaged yet. When used on reactor artifact, copy should be executed after packaging: see MDEP-187.
at org.apache.maven.plugins.dependency.AbstractDependencyMojo.copyFile (AbstractDependencyMojo.java:180)
at org.apache.maven.plugins.dependency.fromDependencies.CopyDependenciesMojo.copyArtifact (CopyDependenciesMojo.java:249)
at org.apache.maven.plugins.dependency.fromDependencies.CopyDependenciesMojo.doExecute (CopyDependenciesMojo.java:124)
at org.apache.maven.plugins.dependency.AbstractDependencyMojo.execute (AbstractDependencyMojo.java:143)
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.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:569)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[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 :files
(base) [root@rocky8 views]#
問題説明 報錯關鍵字
MDEP-187表示在多模塊構建時,maven-dependency-plugin 試圖複製尚未打包的依賴, 導致當前模塊找不到目標artifact文件(即 jar 未生成),從而觸發構建失敗。
其根因是 copy-dependencies 階段執行得過早,還沒到 artifact 打包完畢的生命週期階段。
二、問題根因分析
1、執行階段錯誤
在原始配置中,copy-dependencies 位於 generate-resources 階段:
<execution>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<includeScope>runtime</includeScope>
</configuration>
</execution>
而 Maven 的生命週期順序中:
validate → compile → test → package → verify → install → deploy
在 generate-resources 階段執行 copy-dependencies,意味着此時依賴 jar 尚未打包生成,因此出現:
Artifact has not been packaged yet
即:maven-dependency-plugin 在嘗試複製目標 jar 時發現文件不存在。
三、修復點一:修改 capacity-scheduler 模塊
contrib/views/capacity-scheduler/pom.xml
1、原始配置(錯誤示例)
<execution>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<includeScope>runtime</includeScope>
</configuration>
</execution>
2、修改方案
將執行階段調整為 prepare-package,同時指定輸出目錄到 classes/WEB-INF/lib:
<!-- 複製運行時依賴到 classes/WEB-INF/lib;放到 prepare-package,避免 MDEP-187 -->
<execution>
<id>copy-lib-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- 直接寫進 target/classes/WEB-INF/lib -->
<outputDirectory>${project.build.outputDirectory}/WEB-INF/lib</outputDirectory>
<includeScope>runtime</includeScope>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
3、註釋掉原 lib 拷貝資源段
<!-- 註釋掉舊資源拷貝段 -->
<!--
<resource>
<targetPath>WEB-INF/lib</targetPath>
<filtering>false</filtering>
<directory>target/lib</directory>
</resource>
-->
四、修復點二:修改 files 模塊
contrib/views/files/pom.xml
1、原始配置
<execution>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<includeScope>runtime</includeScope>
</configuration>
</execution>
2、替換後的正確寫法
<!-- 在 prepare-package 再複製依賴,避免 MDEP-187,並直接進 classes/WEB-INF/lib -->
<execution>
<id>copy-lib-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/WEB-INF/lib</outputDirectory>
<includeScope>runtime</includeScope>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
五、驗證與重新編譯
兩處修改完成後,重新執行編譯命令:
# 使用 JDK 17
export JAVA_HOME=/opt/modules/jdk-17.0.2
export PATH=$JAVA_HOME/bin:$PATH
java -version
# 編譯 Views 子模塊
cd /opt/modules/ambari3/contrib/views
mvn clean install -DskipTests
編譯結果 當日志顯示 所有 Views 模塊 SUCCESS,即代表 MDEP-187 已修復。
六、補丁方式自動修復(推薦)
如果你使用的是 ambari-env 環境,可以直接使用補丁腳本修復:
https://github.com/TtBigdata/ambari-env/blob/dev/scripts/build/ambari3/common/patch2_2_1/patch2-VIEWS-COMPILE-FIXED.diff
該補丁會自動調整兩個 POM 文件中的執行階段與路徑,確保後續構建穩定。