7

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

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

    <profiles>
      <profile>
        <id>nexus</id>
        <properties>
          <dist.url>http://host.com/nexus/content/repositories</dist.url>
        </properties>
      </profile>
    </profiles>
    
    <activeProfiles>
      <activeProfile>nexus</activeProfile>
    </activeProfiles>
    
  • Parent's pom.xml
    使用定义的属性来组成存储库的 URL。

    <distributionManagement>
      <repository>
        <id>nexus</id>
        <url>${dist.url}/releases</url>
      </repository>
    </distributionManagement>
    
  • 执行的命令:

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

    [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,它找不到该配置文件。

我发现规避这种情况的唯一方法是通过使用插件参数“包装”settings.xml的 Maven 命令行参数手动指定文件的位置,如-sarguments

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

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

更多信息:

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

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

4

1 回答 1

10

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

于 2012-08-01T21:32:27.457 回答