1

我已经根据使用 Github、Bintray 和 maven-release-plugin 发布版本(Andreas Veithen 的博客文章)为 Java 项目设置了 maven 构建。

我的pom版本是 1.0.2-SNAPSHOT,我已经1.0.2在我的 bintray 包中创建了相应的版本。我执行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>
4

3 回答 3

1

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

还要考虑这一点:您可以使用 oss.jfrog.org 来托管您的快照并在推送到 Bintray 期间自动转换为版本。

  • 缺点 - 对于仅链接到 jcenter 的开源项目
  • 优势 -其他一切:) 用于开发过程的免费 Artifactory 实例,与任何 CI 服务器(托管或云)集成,通过单个 rest API 调用透明地发布到 Bintray。
于 2014-04-09T06:35:28.760 回答
1

在 mavenmvn 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>><repository>部分中)。

bintray-api-key值可以在Bintray 配置文件设置的 API Key 部分中生成。


不要使用mvn deployfor 执行释放

错误地,我最初尝试mvn deploy(尝试推送 a *-SNAPSHOT)而不是mvn release:prepare+ mvn release:perform(正确创建并推送发布)。

于 2014-07-22T23:16:42.843 回答
0

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

于 2014-05-30T22:14:51.553 回答