由于未能构建依赖项的发布版本,Maven 发布构建在 Jenkins 中失败

Posted

技术标签:

【中文标题】由于未能构建依赖项的发布版本,Maven 发布构建在 Jenkins 中失败【英文标题】:Maven release build fails in Jenkins due to failure to build a release version of dependency 【发布时间】:2015-12-07 10:05:18 【问题描述】:

由于 MODULE 2 找不到 MODULE 1 的发布版本而导致 EAR 应用程序的 Maven 发布构建失败。

Maven 版本 是 2.2.1。 Maven 命令: --batch-mode release:prepare release:perform -DdryRun=false -Darguments='-Dmaven.test.skip=true' -e

日志摘录:

------------------------------------------------------------------------
[INFO] [INFO] Building MODULE 1
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] [resources:resources execution: default-resources]
[INFO] [INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] [INFO] skip non existing resourceDirectory /home/jenkins/workspace/repo-trunk-release/target/checkout/module-1-trunk-release/src/main/resources
[INFO] [INFO] [compiler:compile execution: default-compile]
[INFO] [INFO] Changes detected - recompiling the module!
[INFO] [INFO] Compiling 120 source files to /home/jenkins/workspace/repo-trunk-release/target/checkout/module-1-trunk-release/target/classes
[INFO] [WARNING] /home/jenkins/workspace/repo-trunk-release/target/checkout/module-1-trunk-release/src/main/java/com/.../SomeClass.java: Some input files use or override a deprecated API.
[INFO] [WARNING] /home/jenkins/workspace/repo-trunk-release/target/checkout/module-1-trunk-release/src/main/java/com/.../SomeClass.java: Recompile with -Xlint:deprecation for details.
[INFO] [WARNING] /home/jenkins/workspace/repo-trunk-release/target/checkout/module-1-trunk-release/src/main/java/com/.../SomeClass.java: Some input files use unchecked or unsafe operations.
[INFO] [WARNING] /home/jenkins/workspace/repo-trunk-release/target/checkout/module-1-trunk-release/src/main/java/com/.../SomeClass.java: Recompile with -Xlint:unchecked for details.
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Building MODULE 2
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] [resources:resources execution: default-resources]
[INFO] [INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] [INFO] Copying 6 resources
[INFO] Downloading: http:.../nexus/.../module-1-trunk-release/11.0.29/module-1-trunk-release-11.0.29.jar
[INFO] [INFO] Unable to find resource '....apps:module-1-trunk-release:jar:11.0.29' in repository central (http://.../nexus/content/groups/public)
[INFO] Downloading:.http//../nexus/content/repositories/.../module-1-trunk-release/11.0.29/module-1-trunk-release-11.0.29.jar
[INFO] [WARNING] Unable to get resource '....apps:module-1-trunk-release:jar:11.0.29' from repository secondary (http://.../nexus/content/repositories/...-releases): Error transferring file: Connection refused
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [ERROR] BUILD ERROR
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Failed to resolve artifact.
[INFO] 
[INFO] Missing:
[INFO] ----------
[INFO] 1) ....apps:module-1-trunk-release:jar:11.0.29
[INFO] 
[INFO]   Try downloading the file manually from the project website.
[INFO] 
[INFO]   Then, install it using the command: 
[INFO]       mvn install:install-file -DgroupId=....apps -DartifactId=module-1-trunk-release -Dversion=11.0.29 -Dpackaging=jar -Dfile=/path/to/file
[INFO] 
[INFO]   Alternatively, if you host your own repository you can deploy the file there: 
[INFO]       mvn deploy:deploy-file -DgroupId=....apps -DartifactId=module-1-trunk-release -Dversion=11.0.29 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
[INFO] 
[INFO]   Path to dependency: 
[INFO]      1) ....apps:module-2:jar:11.0.29
[INFO]      2) ....apps:module-1:jar:11.0.29
[INFO] 
[INFO] ----------
[INFO] 1 required artifact is missing.
[INFO] 
[INFO] for artifact: 
[INFO]   ....apps:module-2:jar:11.0.29
[INFO] 
[INFO] from the specified remote repositories:
[INFO]   repo-pub1 (http://..../nexus/content/repositories/...-releases),
[INFO]   repo-pub2 (http://..../nexus/content/groups/public)
[INFO] 
[INFO] 
[INFO] 
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] For more information, run Maven with the -e switch
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 42 seconds
[INFO] [INFO] Finished at: Thu Dec 03 17:18:49 GMT 2015
[INFO] [INFO] Final Memory: 99M/438M
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Maven execution failed, exit code: '1'

[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Maven execution failed, exit code: '1'
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:284)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.lifecycle.LifecycleExecutorInterceptor.execute(LifecycleExecutorInterceptor.java:65)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at hudson.maven.agent.Main.launch(Main.java:205)
    at hudson.maven.MavenBuilder.call(MavenBuilder.java:154)
    at hudson.maven.Maven2Builder.call(Maven2Builder.java:79)
    at hudson.maven.Maven2Builder.call(Maven2Builder.java:55)
    at hudson.remoting.UserRequest.perform(UserRequest.java:120)
    at hudson.remoting.UserRequest.perform(UserRequest.java:48)
    at hudson.remoting.Request$2.run(Request.java:326)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.maven.plugin.MojoExecutionException: Maven execution failed, exit code: '1'
    at org.apache.maven.plugins.release.PerformReleaseMojo.execute(PerformReleaseMojo.java:174)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at hudson.maven.agent.PluginManagerInterceptor.executeMojo(PluginManagerInterceptor.java:182)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    ... 27 more
Caused by: org.apache.maven.shared.release.ReleaseExecutionException: Maven execution failed, exit code: '1'
    at org.apache.maven.shared.release.phase.AbstractRunGoalsPhase.execute(AbstractRunGoalsPhase.java:91)
    at org.apache.maven.shared.release.phase.RunPerformGoalsPhase.runLogic(RunPerformGoalsPhase.java:135)
    at org.apache.maven.shared.release.phase.RunPerformGoalsPhase.execute(RunPerformGoalsPhase.java:46)
    at org.apache.maven.shared.release.DefaultReleaseManager.perform(DefaultReleaseManager.java:429)
    at org.apache.maven.shared.release.DefaultReleaseManager.perform(DefaultReleaseManager.java:381)
    at org.apache.maven.plugins.release.PerformReleaseMojo.execute(PerformReleaseMojo.java:170)
    ... 30 more
Caused by: org.apache.maven.shared.release.exec.MavenExecutorException: Maven execution failed, exit code: '1'
    at org.apache.maven.shared.release.exec.InvokerMavenExecutor.executeGoals(InvokerMavenExecutor.java:433)
    at org.apache.maven.shared.release.exec.AbstractMavenExecutor.executeGoals(AbstractMavenExecutor.java:114)
    at org.apache.maven.shared.release.phase.AbstractRunGoalsPhase.execute(AbstractRunGoalsPhase.java:85)
    ... 35 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 minutes 27 seconds
[INFO] Finished at: Thu Dec 03 17:18:50 GMT 2015
[INFO] Final Memory: 33M/404M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving /home/jenkins/workspace/repo-trunk-release/pom.xml to ....apps/.../11.0.29-SNAPSHOT/repo-trunk-release-11.0.29-SNAPSHOT.pom
channel stopped
Finished: FAILURE

【问题讨论】:

首先我会leave Maven 2.2.1 此外你使用哪个版本的maven-release-plugin?除此之外,这看起来是错误的`传输文件时出错:连接被拒绝 maven-release-plugin 是 2.5.2。尝试了 maven 3.3.9 但得到了不同的错误。 @khmarbaise 文件传输错误可能更多地与配置错误的辅助 nexus 存储库有关。通常 build 会期望从 main nexus repo 获得 MODULE 1。不要认为这与发布构建失败的主要问题有关。 ear 模块是否包含 module1 和 module2(使用类似战争或类似的?)...这是多模块构建吗?模块之间是否存在正确的依赖关系? @khmarbaise 是的,它是多模块 - EAR 带有用于 EJB 的 jar,它还构建了一个 WAR Web 应用程序。在这种情况下构建的版本是 11.0.29,模块 1 和模块 2 也应该构建为 11.0.29,基于使用:<dependency> <groupId>com.module.one</groupId> <artifactId>module-1</artifactId> <version>$project.version</version> </dependency> 【参考方案1】:

固定构建,这就是方法。 我首先在 Jenkins 配置中切换到 maven 3.0.2,因为正如所暗示的那样 @khmarbaise 使用 maven 2.2.1 是问题的根源。

但后来我得到了 wsimport 错误,为了修复这些我删除了编码属性

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

来自父 pom。

然后我得到了很多类型的编码错误,

error: unmappable character for encoding ANSI_X3.4-1968

为了解决这些问题,我添加了

-Dfile.encoding=UTF8 

到 Jenkins 作业配置中的 to MAVEN OPTS 道具。

编码错误与 JavaDoc 和应用程序代码中其他地方存在大量“奇怪”字符有关。

【讨论】:

以上是关于由于未能构建依赖项的发布版本,Maven 发布构建在 Jenkins 中失败的主要内容,如果未能解决你的问题,请参考以下文章

是否有一个 Maven 插件可以验证传递依赖项的冲突版本?

如何使用不打包任何依赖项的 maven 程序集插件构建 jar?

gradle 到 maven 的转换,在依赖项的依赖项的版本名称中解析通配符“+”?

Maven:在不扩展依赖项的情况下使用 flatten 解析版本

maven发布jar固定版本缓存问题

mvn 命令用于更新依赖项中的版本和一个使用该依赖项的项目