【问题标题】:Deploying to bintray from Maven fails从 Maven 部署到 bintray 失败
【发布时间】:2014-04-08 16:08:10
【问题描述】:

我已经根据 Andreas Veithen 的博客文章 Publishing releases using Github, Bintray and maven-release-plugin 为 Java 项目设置了 maven 构建。

我的pom 版本是1.0.2-SNAPSHOT,我在我的bintray 包中创建了相应的版本1.0.2。我执行mvn -Prelease clean install,没问题。我执行mvn release:prepare,没问题。但是当我执行mvn release:perform 时,构建中断并出现以下错误消息。

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy 
(default-deploy) on project [PROJECT]: Failed to deploy artifacts: Could not 
transfer artifact my.project:test:jar:1.0.2-20140408.154954-1 from/to bintray-
user-maven-package (https://api.bintray.com/maven/user/maven/package): Failed to 
transfer file: https://api.bintray.com/maven/user/maven/package/my/project/test/
1.0.2-SNAPSHOT/test-1.0.2-20140408.154954-1.jar. Return code is: 400, 
ReasonPhrase: Bad Request. -> [Help 1]

我注意到发布插件正在尝试上传 SNAPSHOT,当然这在 bintray 上应该没有位置...我原以为它会尝试部署 1.0.2?如何说服 maven 上传正确的工件,或者我的设置有什么问题?

以下是我认为相关的 POM 部分,完整的 POM 位于 pastebin

<modelVersion>4.0.0</modelVersion>
<groupId>my.tool</groupId>
<artifactId>util</artifactId>
<packaging>jar</packaging>
<version>1.0.2-SNAPSHOT</version>

<scm>
  <connection>scm:git:https://github.com/user/package.git</connection>
  <developerConnection>scm:git:git@github.com:user/package.git</developerConnection>
  <url>https://github.com/user/package</url>
  <tag>HEAD</tag>
</scm>

<distributionManagement>
  <repository>
    <id>bintray-user-maven-package</id>
    <name>user-maven-package</name>
    <url>https://api.bintray.com/maven/user/maven/package</url>
  </repository>
</distributionManagement>

<profile>
    <id>release</id>
    <build>
      <plugins>
        <plugin>
          <artifactId>maven-source-plugin</artifactId>
          <executions>
            <execution>
              <id>attach-sources</id>
              <goals>
                <goal>jar</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <artifactId>maven-javadoc-plugin</artifactId>
          <executions>
            <execution>
              <id>attach-javadocs</id>
              <goals>
                <goal>jar</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
  </profile>
</profiles>

<build>
 <defaultGoal>install</defaultGoal>
 <plugins>
      <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-compiler-plugin</artifactId>
           <version>3.1</version>
           <configuration>
                <source>1.7</source>
                <target>1.7</target>
           </configuration>
      </plugin>
      <plugin>
            <groupId>com.mycila</groupId>
            <artifactId>license-maven-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <header>${basedir}/src/etc/header.txt</header>
                <includes>
                    <include>src/main/java/**</include>
                    <include>src/test/java/**</include>
                </includes>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.5</version>
          <configuration>
            <useReleaseProfile>false</useReleaseProfile>
            <releaseProfiles>release</releaseProfiles>
            <autoVersionSubmodules>true</autoVersionSubmodules>
          </configuration>
        </plugin>
  </plugins>
</build>

【问题讨论】:

  • 您确定要发布 1.0.2 而不是 1.0.1?因为我希望 Maven 在 1.0.1 发布后尝试部署 1.0.2-SNAPSHOT。
  • @JBaruch:抱歉,在几次发布失败后,我进行了多次硬重置并删除了标签。我再次将 POM 版本更改为 1.0.2-SNAPSHOT...

标签: java maven deployment maven-release-plugin bintray


【解决方案1】:

您必须发布您的 pom 以了解您的 maven 发布插件配置有什么问题。

还要考虑这个: 您可以使用 oss.jfrog.org 到 host your snapshots 并在推送到 Bintray 期间自动转换为发布。

  • 缺点 - 对于仅链接到 jcenter 的开源项目
  • 优势 - everything else :) 用于开发过程的免费 Artifactory 实例,与任何 CI 服务器(托管或云)集成,通过单个 rest API 调用透明地发布到 Bintray。

【讨论】:

  • 谢谢。在问题中添加了相关的 POM 摘录,并将整个内容放在 pastebin 中。
【解决方案2】:

在 maven mvn release:perform 步骤期间,文件应传输到:

https://api.bintray.com/maven/user/maven/package/my/project/test/1.0.2

而不是:

https://api.bintray.com/maven/user/maven/package/my/project/test/1.0.2-SNAPSHOT

这就是 Bintray 正确返回的原因:

Return code is: 400, ReasonPhrase: Bad Request.

将 maven-release-plugin 从(我的)v2.2.2 升级到当前最新的 v2.5 为我修复了它。升级后,mvn release:prepare 步骤的行为有所不同。


返回码是:401

正如@vorburger 在评论中提到的那样,如果(使用 maven-deploy-plugin:2.7)Bintray 返回:

Return code is: 401, ReasonPhrase: Unauthorized.

那么“只是”意味着您在settings.xml 中没有&lt;server&gt; 的用户名和密码或密码错误:

<server>
  <id>{matching-id}</id>
  <username>{bintray-user}</username>
  <password>{bintray-api-key}</password>
</server>

matching-id 值应与pom.xml 文件中定义的值相同(在&lt;distributionManagement&gt; > &lt;repository&gt; 部分中)。

bintray-api-key 值可以在API Key section of the Bintray profile settings 中生成。


不要使用mvn deploy 来执行发布

错误地我最初尝试了mvn deploy(它试图推送*-SNAPSHOT)而不是mvn release:prepare + mvn release:perform(它正确地创建并推送了一个版本)。

【讨论】:

  • PS:如果不是“返回码是:400,ReasonPhrase:错误请求。”你点击了“返回码是:401,ReasonPhrase:未经授权。”来自api.bintray.com/maven...(使用 maven-deploy-plugin:2.7),那么“只是”意味着您没有或错误的 用户名和密码(匹配 ...) settings.xml。
【解决方案3】:

我遇到了同样的问题。将 maven-release-plugin 降级到 2.4 版解决了我的问题。

【讨论】:

    猜你喜欢
    • 2012-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多