从Maven部署到bintray失败了

时间:2014-04-08 16:08:11

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

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

我的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>

3 个答案:

答案 0 :(得分:1)

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

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

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

答案 1 :(得分:1)

在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从(my)v2.2.2升级到当前最新的v2.5,为我修复了它。升级后,mvn release:prepare步骤表现不同。


返回代码是:401

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

Return code is: 401, ReasonPhrase: Unauthorized.

然后“只是”意味着<server>中的settings.xml没有或错误的用户名和密码:

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

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

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


不要使用mvn deploy来执行发布

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

答案 2 :(得分:0)

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