从 Maven 版本中分叉出来的进程:执行插件忽略用户的 settings.xml? [英] Process forked out of Maven release:perform plugin ignores user's settings.xml?

查看:90
本文介绍了从 Maven 版本中分叉出来的进程:执行插件忽略用户的 settings.xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档,Maven 发布:执行目标检查项目,然后派生一个新的 Maven 实例来构建它.出于某种原因,分叉实例似乎忽略了用户的 settings.xml,这在我的情况下会导致错误,因为该文件具有用于组成父 pom 中存储库 URL 的属性的定义.

As per the documentation, the Maven release:perform goal checks out the project and then forks a new Maven instance to build it. For some reason the forked instance appears to ignore the user's settings.xml, which causes an error in my case because that file has the definition of a property that is used to compose the repository's URL in the parent pom.

  • 用户的settings.xml
    定义始终处于活动状态的nexus"配置文件中的属性.

  • User's settings.xml
    Definition of a property in a "nexus" profile which is always active.

<profiles>
  <profile>
    <id>nexus</id>
    <properties>
      <dist.url>http://host.com/nexus/content/repositories</dist.url>
    </properties>
  </profile>
</profiles>

<activeProfiles>
  <activeProfile>nexus</activeProfile>
</activeProfiles>

  • 父母的pom.xml
    使用定义的属性来组成存储库的 URL.

  • Parent's pom.xml
    Usage of the defined property to compose the repository's URL.

    <distributionManagement>
      <repository>
        <id>nexus</id>
        <url>${dist.url}/releases</url>
      </repository>
    </distributionManagement>
    

  • 执行的命令:

  • Command executed:

    mvn release:perform
    

  • 输出(在它表示已成功签出、构建、测试和打包项目之后):

  • Output (after it indicates having successfully checked out, built, tested and packaged the project):

    [INFO] Uploading: ${dist.url}/releases/com/acme/access/my-project/1.0/my-project-1.0.jar
    [INFO] [INFO] ------------------------------------------------------------------------
    [INFO] [INFO] BUILD FAILURE
    [INFO] [INFO] ------------------------------------------------------------------------
    [INFO] [INFO] Total time: 3.659s
    [INFO] [INFO] Finished at: Wed Aug 01 14:40:23 EDT 2012
    [INFO] [INFO] Final Memory: 21M/307M
    [INFO] [INFO] ------------------------------------------------------------------------
    [INFO] [WARNING] The requested profile "nexus" could not be activated because it does not exist.
    [INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project my-project: Failed to deploy artifacts: Could not transfer artifact com.acme.access:my-project:jar:1.0 from/to nexus (${dist.url}/releases): Error transferring file: no protocol: ${dist.url}/releases/com/acme/access/my-project/1.0/my-project-1.0.jar -> [Help 1]
    

  • 注意分叉的 Maven 实例如何尝试上传到 ${dist.url},这表明 settings.xml 中定义的属性没有被读取.此外,警告消息通知未找到配置文件nexus".我假设主 Maven 实例将配置文件信息传递给分叉实例,因此它知道要查找它,但由于它忽略(或未找到)用户的 settings.xml,它无法找到该配置文件.

    Notice how the forked Maven instance is trying to upload to ${dist.url}, which indicates that the property defined in settings.xml was not read. Also, the warning message informs that profile "nexus" was not found. I'm assuming that the main Maven instance passed the profile information down to the forked instance so it knew to look for it, but since it ignored (or did not find) the user's settings.xml, it could not find that profile.

    我发现绕过这个的唯一方法是通过使用Maven的命令行-s参数wrapped"手动指定settings.xml文件的位置" 通过插件的 arguments 参数,如

    The only way I have found to circumvent this is to manually specify the location of the settings.xml file through the use of Maven's command line -s argument "wrapped" by the plugin's arguments argument, as in

    mvn release:perform -Darguments="-s C:\Users\theuser\.m2\settings.xml"
    

    插件是否以预期/正确的方式运行?有没有办法将属性定义保留在用户的 settings.xml 中,而不必像我上面所做的那样指定文件的位置?

    Is the plugin behaving in an expected/correct way? Is there a way to keep the property definition inside the user's settings.xml without having to specify the location of the file as I have done above?

    更多信息:

    • 问题似乎特别在于插件找不到用户的 settings.xml,因为将配置文件信息复制到全局 settings.xml 确实会导致它工作.

    • The problem seems to be specifically with the plugin not finding the user's settings.xml, as copying the profile information into the global settings.xml does cause it to work.

    用户的 settings.xml 已正确命名/创建,因为运行 help:active-profiles 表示配置文件处于活动状态.使用 mvn clean deploy 手动构建和部署也能正常工作(即正确计算存储库 URL 并上传工件).

    The user's settings.xml is properly named/created because running help:active-profiles indicates that the profile is active. Manually building and deploying with mvn clean deploy also works correctly (ie, the repository URL is correctly calculated and the artifact is uploaded).

    推荐答案

    这不一定是 maven-release-plugin 中的错误.您似乎遇到了这个 Maven 错误:MNG-5224该错误应在 Maven 3.0.4 中修复.

    It's not necessarily a bug in the maven-release-plugin. It seems that you ran into this Maven bug: MNG-5224 The bug should be fixed in Maven 3.0.4.

    这篇关于从 Maven 版本中分叉出来的进程:执行插件忽略用户的 settings.xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆