Maven 发布插件失败:源工件部署两次
我们正在 hudson 上使用 Maven 发布插件,并尝试自动化发布过程。 发布:准备工作正常。当我们尝试执行release:perform时,它失败了,因为它尝试将源工件两次上传到存储库。
我尝试过的事情,
- 从超级 pom 中删除包含 Maven 源插件的配置文件(不起作用),
- 将 hudson 上的发布目标指定为 -P!attach-source release:prepare release:perform。我认为这会排除源插件的执行。 (没用)。
- 尝试将插件阶段指定为超级 pom 中某个不存在的阶段。(不起作用)
- 尝试指定插件配置,forReleaseProfile 为 false。 (你猜怎么着?也不起作用)
它仍然吐出这个错误。
[INFO] [DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[INFO] [DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[INFO] [DEBUG] Checking for pre-existing User-Agent configuration.
[INFO] [DEBUG] Adding User-Agent configuration.
[INFO] [DEBUG] not adding permissions to wagon connection
[INFO] Uploading: http://xx.xx.xx.xx:8081/nexus/content/repositories/releases//com/yyy/xxx/hhh/hhh-hhh/1.9.40/hhh-hhh-1.9.40-sources.jar
[INFO] 57K uploaded (xxx-xxx-1.9.40-sources.jar)
[INFO] [DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[INFO] [DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[INFO] [DEBUG] Checking for pre-existing User-Agent configuration.
[INFO] [DEBUG] Adding User-Agent configuration.
[INFO] [DEBUG] not adding permissions to wagon connection
[INFO] Uploading: http://xx.xxx.xx.xx:8081/nexus/content/repositories/releases//com/xxx/xxxx/xxx/xxx-xxx/1.9.40/xxx-xxx-1.9.40-sources.jar
[INFO] [DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [ERROR] BUILD ERROR
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Error deploying artifact: Authorization failed: Access denied to: http://xx.xxx.xx.xx:8081/nexus/content/repositories/releases/com/xxx/xxx/xxx/xxx-config/1.9.40/xxx-xxx-1.9.40-sources.jar
任何与此相关的帮助将不胜感激。
We are using the maven release plugin on hudson and trying to automate the release process.
The release:prepare works fine. When we try to do the release:perform , it fails because it tries to upload a source artifact twice to the repository.
Things that I tried,
- removing the profile which does include the maven source plugin from the super pom ( did not work)
- specifying the goals on hudson for release as -P!attach-source release:prepare release:perform. Which I thought will exclude the source plugin from getting executed. (did not work).
- tried specifying the plugin phase to some non existent phase in the super pom.(Did not work)
- tried specifying the plugin configuration, forReleaseProfile as false. ( guess what?? Did not work too)
It still spits out this error.
[INFO] [DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[INFO] [DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[INFO] [DEBUG] Checking for pre-existing User-Agent configuration.
[INFO] [DEBUG] Adding User-Agent configuration.
[INFO] [DEBUG] not adding permissions to wagon connection
[INFO] Uploading: http://xx.xx.xx.xx:8081/nexus/content/repositories/releases//com/yyy/xxx/hhh/hhh-hhh/1.9.40/hhh-hhh-1.9.40-sources.jar
[INFO] 57K uploaded (xxx-xxx-1.9.40-sources.jar)
[INFO] [DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[INFO] [DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[INFO] [DEBUG] Checking for pre-existing User-Agent configuration.
[INFO] [DEBUG] Adding User-Agent configuration.
[INFO] [DEBUG] not adding permissions to wagon connection
[INFO] Uploading: http://xx.xxx.xx.xx:8081/nexus/content/repositories/releases//com/xxx/xxxx/xxx/xxx-xxx/1.9.40/xxx-xxx-1.9.40-sources.jar
[INFO] [DEBUG] Using Wagon implementation lightweight from default mapping for protocol http
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [ERROR] BUILD ERROR
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Error deploying artifact: Authorization failed: Access denied to: http://xx.xxx.xx.xx:8081/nexus/content/repositories/releases/com/xxx/xxx/xxx/xxx-config/1.9.40/xxx-xxx-1.9.40-sources.jar
Any help regarding this will be really appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
尝试运行
mvn -Prelease-profile help: effective-pom
。您会发现
maven-source-plugin
有两个执行部分,输出将如下所示:
要解决此问题,请找到您使用过
maven-source-plugin
的所有位置,并确保使用“id”附加源,以便它与发布配置文件相同。然后这些部分将被合并。最佳实践表明,为了获得一致性,您需要在项目的根 POM 中的 build > 中进行配置。在您的子 pom 中使用pluginManagement 和NOT。在子 pom 中,您只需在 build > 中指定您想要使用 maven-source-plugin 但未提供任何执行的插件。
在根 pom.xml 中:
在子 pom.xml 中:
Try running
mvn -Prelease-profile help:effective-pom
.You will find that you have two execution sections for
maven-source-plugin
The output will look something like this:
To fix this problem, find everywhere you have used
maven-source-plugin
and make sure that you use the "id" attach-sources so that it is the same as the release profile. Then these sections will be merged.Best practice says that to get consistency you need to configure this in the root POM of your project in build > pluginManagement and NOT in your child poms. In the child pom you just specify in build > plugins that you want to use maven-source-plugin but you provide no executions.
In the root pom.xml:
In the child pom.xml:
我知道这个问题很老了,但今天谷歌点击了#1,所以我将添加适合最新版本的 Maven 3 的答案。
症状是,在使用某些版本的 Maven 进行发布构建时,源和 javadoc jar 被部署了两次3. 如果您使用 maven 将工件部署到仅允许上传一次发布工件的 Sonatype Nexus 存储库(这是完全合理的行为),则当第二次上传尝试被拒绝时,构建会失败。啊!
Maven 版本 3.2.3 至 3.3.9 有错误 - 请参阅 https://issues.apache。 org/jira/browse/MNG-5868 和 https://issues.apache .org/jira/browse/MNG-5939。这些版本在发布时会生成并部署源代码和 javadoc jar 两次。
如果我正确地阅读了 Maven 问题跟踪器,那么在撰写本文时,这些错误尚未计划修复(烧毁的 3.4.0 版本可能会影响这些错误)。
我的简单解决方法是回退到 Maven 版本 3.2.1,而不是对我的 pom 进行复杂的调整。
I know this question is old but it was google hit #1 today so I'll add my answer appropriate for recent versions of maven 3.
The symptom is that sources and javadoc jars are deployed twice when doing a release build with some versions of maven 3. If you're using maven to deploy your artifacts to a Sonatype Nexus repository that only allows a release artifact to be uploaded once (which is totally reasonable behavior), the build fails when the second upload attempt is rejected. Argh!
Maven versions 3.2.3 thru 3.3.9 have bugs - see https://issues.apache.org/jira/browse/MNG-5868 and https://issues.apache.org/jira/browse/MNG-5939. Those versions generate and deploy sources and javadoc jars twice when doing a release.
If I read the Maven issue tracker correctly, those bugs are not scheduled for fix as of this writing (the burned 3.4.0 release probably affected these).
Instead of a complex tweak to my pom, my simple workaround was to fall back to Maven version 3.2.1.
刚刚遇到同样的问题,我分析了一下。
mvn release:perform
评估release.properties 文件,然后在临时目录中检查标签并调用类似我尝试重现的内容 - 手动检查由
release 生成的标签:准备并调用此:
我得到了相同的结果:它试图上传 -sources.jar 两次。
正如评论中 qualidafial 所指出的,设置
performRelease=false
会忽略两个附件之一同一文件的。我真的不知道 部署插件 (或任何其他插件)使用此属性。
我们可以提供此参数作为 maven-relase-plugin 的配置:
我现在向所有 POM 添加了
false
行,看起来现在发布不需要错误消息。Just having hit the same problem, I analyzed it a bit.
mvn release:perform
evaluates the release.properties file, then checks out the tag in a temporary directory and invokes there something likeI tried to reproduce this – manually checked out the tag produced by
release:prepare
and invoked this:I got the same result: It was trying to upload the -sources.jar twice.
As noted by qualidafial in a comment, setting
performRelease=false
instead omits one of the two attachments of the same file.I don't really have an idea how the deploy plugin (or any other plugin) uses this property.
We can provide this parameter as a configuration to the maven-relase-plugin:
I now added the
<useReleaseProfile>false</useReleaseProfile>
line to all the POMs, and it looks like releasing now works without an error message.我已经在这个问题上苦苦挣扎了一段时间,终于能够在我们的基础设施中解决它。这里的答案对我没有帮助,因为我们没有多次执行源插件目标,并且配置对我们来说似乎很好。
我们错过的是将源插件的执行绑定到一个阶段。扩展 Bae 的示例,包括将
install
行添加到执行中,为我们解决了这个问题:我怀疑解决方案在于这个答案 < a href="https://stackoverflow.com/questions/8041610/maven-plugin-executes-multiple-times-during-build">此处;不同的插件似乎正在调用 jar 目标/附加源执行。通过将我们的执行绑定到某个阶段,我们强制我们的插件仅在该阶段运行。
I have been struggeling with this issue for a while and have finally been able to resolve it in our infrastructure. The answers here didn't help me, as we didn't have multiple executions of the source plugin goals and the configuration seemed fine to us.
What we did miss out was to bind the execution of the source plugin to a phase. Extending the example by Bae, including the line
<phase>install</phase>
to the execution resolved the issue for us:I suspect the solution lies in this answer here; different plugins seem to be invoking the jar goal / the attach-sources execution. By binding our execution to a certain phase, we force our plugin only to be run in this phase.
我在运行时发生了这种情况,
我通过运行(这意味着安装)来避免问题
。在我的例子中,只有一个工件被尝试上传两次,这是一个次要工件(maven-jar-plugin 设置为除了由 default-jar 执行构建的 jar 之外,还构建一个辅助 jar)。
This was happening to me when running
I avoided the problem by instead running
(which implies install). In my case only one artifact was being attempted to be uploaded twice, and that was a secondary artifact (maven-jar-plugin was setup to build a secondary jar in addition to the one built by the default-jar execution).
TL;DR
如果您无法修改父 poms,则使用 id
attach-sources
禁用执行可以修复此问题。--
这个答案是对@Bae答案的补充:
https://stackoverflow.com/a/10794985/3395456
我的问题是一样的,当运行
mvn -Prelease-profile help: effective-pom
时,我有两个 maven-source-plugin 的执行部分投票最高的答案只是建议删除未命名(匿名)的最佳实践)
执行
以避免重复绑定。但是,如果我无法删除它,因为我无法更改父 pom,该怎么办?有一种方法可以禁用一个
执行
,不是匿名执行,而是具有 idattach-source
的执行。它也适用于上传 xx-javadoc.jar 两次。因此,在我的 pom.xml 下,我可以通过 id
attach-source
禁用执行来显式覆盖插件设置。参考:
是否可以覆盖maven插件管理中的执行?
TL;DR
Disable execution with id
attach-sources
fixes this problem, if you cannot modify your parent poms.--
This answer is a supplementary for @Bae's answer:
https://stackoverflow.com/a/10794985/3395456
My problem is the same, when running
mvn -Prelease-profile help:effective-pom
, I have two execution sections for maven-source-pluginThe top voted answer just recommends a best practice to remove unnamed (anonymous)
execution
to avoid duplicated binding. But what if I cannot remove it, because I cannot change the parent pom?There is one way to disable one
execution
, not the anonymous one, but the one with idattach-source
. And it also works for uploadingxx-javadoc.jar
twice.So under my
pom.xml
, I can explictly override the plugins settings, by disabling the execution with idattach-source
.References:
Is it possible to override executions in maven pluginManagement?
我认为问题不在发布插件中,我认为您已经附加了两次
xxx-sources.jar
- 这就是重复上传的原因。如果没有看到 POM,很难判断为什么会有重复的附件。再次尝试运行mvn -X
并检查日志以了解附加xxx-source.jar
的人员。无论如何,Nexus 上的一个好的解决方法是拥有一个临时存储库,您可以在其中多次上传版本 - 当一切准备就绪时,您只需关闭/升级临时存储库即可。查看 Sonatype OSS 设置获取示例。
I don't think the probem is in the release plugin, I think you've got the
xxx-sources.jar
attached two times - that's why the duplicate upload. Why is there a duplicate attachment is hard to tell without seeing the POM. Try runningmvn -X
and checking the log for who attachesxxx-source.jar
another time.In any case, a good workaround on Nexus would be having a staging repository where you can upload releases several times - and when everything's ready you just close/promote the staging repo. Check the Sonatype OSS setup for an example.
我也有同样的问题。基本上,当工件被发送到 Nexus 两次时,就会发出错误消息。对于同一 Nexus 存储库,甚至同一 Nexus 内的不同存储库,这可能是两次。
然而,这种错误配置的原因可能各不相同。就我而言,工件在 Jenkins 中的 mvn clean 部署构建步骤期间正确上传,但在尝试第二次部署时失败。第二次部署已在 Jenkins 构建后步骤“在 Maven 存储库中发布工件”中进行配置。
I had the same problem. Basically, the error message is issued when an artifacts is sent to Nexus twice. This may be twice to the same Nexus repository or even across different repositories within the same Nexus.
However, the reasons for such a misconfiguration may vary. In my case, the artifacts were uploaded correctly during a mvn clean deploy build step in Jenkins, but then failed when a second deploy had been attempted. This second deploy had been configured in a Jenkins post build step "Publish artifacts in Maven repository".
父 pom 和子 pom 中的 Maven 插件不应执行。根据标准约定,在插件管理部分的父 pom 中定义具有执行/目标的所有插件。子pom不应该重新定义上述细节,而只提及需要执行的插件(带有artifactId和版本)。
我对父 pom 的 maven- assembly-plugin 也有类似的问题,如下所示:
子 pom 的 maven- assembly-plugin 如下:
从子 pom 中删除
纠正了该问题。有效的 pom 执行了 2 次,导致重复安装到 Nexus 存储库。
Maven plugins in parent and child poms should not have execution. As per standard convention, define all plugin with execution/goals in parent pom in plugin management section. Child pom should not redefine above details, but mention only the plugin (with artifactId, and version) that needs to be executed.
I had similar issue with maven-assembly-plugin with parent pom as below:
And Child pom had maven-assembly-plugin as below:
Removing the
<executions>
from child pom rectified the issue.The effective pom had 2 executions performed causing the duplicate install to Nexus repo.
FWIW 这个问题在一段时间内破坏了我们的构建,答案不是以上任何一个。
相反,我在一个与我们的主工件附加(读取部署、发布)的工件的 maven-assemble-plugin 中愚蠢地将看似无害的appendAssemblyId 设置为 false。例如:
总而言之:
程序集插件使用 assemblyId 作为工件的分类器,因此它是 Maven 术语中唯一的 GAV 坐标的重要组成部分(实际上它更像是 GAVC 坐标 - C 是分类器)。
已安装、已部署或已发布文件的名称实际上是根据这些坐标构建的。它与您在目标目录中看到的文件名不同。这就是为什么您的本地构建看起来不错,但您的发布将会失败。
愚蠢的元素仅确定本地构建工件名称,并且不参与其余部分。这完全是在转移注意力。
摘要摘要:
来自 Nexus 的 400 错误是因为我们额外附加的工件上传到主工件之上,因为它与主工件同名,因为它与主工件具有相同的 GAVC 坐标,因为我删除了唯一的区别坐标:从 assemblyId 自动派生的分类器。
经过调查发现这是一条漫长而曲折的道路,答案就在 maven-assemble 的文档中:
来自 http://maven.apache.org/plugins /maven- assembly-plugin/single-mojo.html#attach
额外的粗体是我的。文档应该在这里有一个大的闪烁警告:“将其设置为 false 并放弃所有希望”
我从这个关于不同问题的答案中得到了一些帮助 maven-assemble-plugin:如何使用appendAssemblyId
图纳基的解释确实很有帮助。
FWIW this issue was breaking our build for a while and the answer was none-of-the-above.
Instead I had foolishly set the seemingly innocuous appendAssemblyId to false in a maven-assembly-plugin for an artifact that gets attached (read deployed, released) with our main artifact. E.g.:
In summary:
the assembly plugin uses the assemblyId as the classifier for the artifact, hence an essential part of it's unique GAV coordinates in maven terms (actually it's more like GAVC coordinates - C is the classifier).
the name of the file installed, deployed, or released is actually built from these coordinates. It is not the same as the filename you see in your target directory. That's why your local build looks good, but your release will fail.
The stupid element only determines the local build artifact name and plays no part in the rest of it. It's a complete red-herring.
Summary of the summary:
The 400 error from Nexus was because our extra attached artifact was being uploaded over top of the main artifact, since it had the same name as the main artifact, because it had the same GAVC coordinates as the main artifact, because I removed the only distinguishing coordinate: the classifier derived automatically from the assemblyId.
The investigation to find this was a long and tortuous path the answer was right there all along in the docs for maven-assembly:
From http://maven.apache.org/plugins/maven-assembly-plugin/single-mojo.html#attach
The extra bold is mine. The docs should have a big flashing warning here: "Set this to false and abandon all hope"
I got some help from this answer about a different problem maven-assembly-plugin: How to use appendAssemblyId
The explanation there from tunaki really helped.
我遇到了类似的问题。工件部署了两次,最终的构建失败了。
检查发现问题出在Jenkins脚本上。 settings.xml 被调用了两次。例如:
sh“mvn -s settings.xml clean deploy -s settings.xml deploy -U .....
这导致了问题。
更新了这一行,它的工作方式就像一个魅力:
sh "mvn clean deploy -s settings.xml -U .....
I faced similar issue. Artifacts were getting deployed twice and the resultant build was failing.
Checked and found that the issue was in Jenkins Script. The settings.xml was called twice. Like:
sh "mvn -s settings.xml clean deploy -s settings.xml deploy -U .....
which caused the issue.
Updated this line and it worked like a charm:
sh "mvn clean deploy -s settings.xml -U .....
Nexus thix 配置对我有用
with nexus thix configuratio nworked for me
我使用releaseProfile = false配置了maven发布插件,并且不执行源工件配置文件。这成功了。
I configured the maven release plug-in with releaseProfile=false and dont execute the source artifacts profile. Which did the trick.