对于将快照发布到BinTray的过程感到困惑

6
我想调查将Hibernate ORM jars发布到Bintray的方法。然而,我们有一个要求是能够发布快照版本,我看到Bintray现在通过这个OJO存储库支持快照版本。但是,阅读文档后,我感到非常困惑,不知道应该如何操作。
首先,文档提到我应该能够请求发布到JCenter,并且同时能够请求发布快照版本。然而,我没有看到任何这样的选项:https://bintray.com/hibernate/artifacts/hibernate-orm 其次,在我设置好OJO帐户之后,我需要对Bintray/Gradle插件进行特殊处理吗?

这是一项有关Bintray Gradle插件的开放性问题/问题已经存在6个月了:https://github.com/bintray/gradle-bintray-plugin/issues/191 - Steve Ebersole
1个回答

6

经过多次尝试和错误,我最终使用了以下设置。

我们使用2个不同的插件进行发布:

  • 快照和发布发布(使用com.jfrog.artifactory
  • 与Bintray相关的活动(在项目p6spy中使用com.jfrog.bintray)。

下面是来自build.gradle文件的相关部分,请注意该项目的具体内容:

plugins {
    ...
    // to publish !SNAPSHOTs to bintray and sync it to maven-central
    // ./gradlew bintrayUpload
    id 'com.jfrog.bintray' version '1.7.3'
    // to publish SNAPSHOTs and !SNAPSHOTs to oss.jfrog.org
    // ./gradlew artifactoryPublish
    id 'com.jfrog.artifactory' version '4.5.2'
}

publishing {
  publications {
    maven(MavenPublication) {
      from components.java
      groupId project.group
      artifactId project.archivesBaseName
      version project.version

      ...

      pom {
        packaging 'jar'
        withXml {
          asNode().children().last() + {
            def builder = delegate

            // maven central publishing mandatories
            builder.name project.name
            builder.description description
            builder.url 'https://github.com/p6spy/p6spy'

            builder.licenses {
                builder.license {
                  builder.name 'The Apache Software License, Version 2.0'
                  builder.url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                  builder.distribution 'repo'
                }
            }
            builder.scm {
                builder.url 'http://github.com/p6spy/p6spy'
                builder.connection 'scm:git:git://github.com/p6spy/p6spy.git'
                builder.developerConnection 'scm:git:ssh://github.com:p6spy/p6spy.git'
            }
            builder.developers {
                builder.developer {
                  builder.name 'Quinton McCombs'
                  builder.email 'quinton.mccombs@gmail.com'
                }
                builder.developer {
                  builder.name 'Peter Butkovic'
                  builder.email 'butkovic@gmail.com'
                }
                builder.developer {
                  builder.name 'Felix Barnsteiner'
                  builder.email 'felix.barnsteiner@isys-software.de'
                }
            }

            // maven central publishing optionals
            builder.issueManagement {
              builder.system 'github'
              builder.url 'https://github.com/p6spy/p6spy/issues'
            }
            builder.ciManagement {
              builder.system 'Travis CI'
              builder.url 'https://travis-ci.org/p6spy/p6spy'
            }
          }
        }
      }
    }
  }
}

// to publish SNAPSHOTs to http://oss.jfrog.org/oss-snapshot-local/ 
// and !SNAPSHOTs to http://oss.jfrog.org/oss-release-local/
artifactory {
    contextUrl = 'https://oss.jfrog.org'
    resolve {
        repository {
            repoKey = 'libs-release'
        }
    }
    publish {
        repository {
            // The Artifactory repository key to publish to
            // when using oss.jfrog.org the credentials are from Bintray.
            if (project.version.endsWith("-SNAPSHOT")) {
              repoKey = 'oss-snapshot-local'
            } else {
              repoKey = 'oss-release-local' 
            }

            username = System.getenv('BINTRAY_USER')
            password = System.getenv('BINTRAY_API_KEY')
        }
        defaults {
            publications 'maven'
            properties = [ 'bintray.repo': 'p6spy/maven', 'bintray.package': 'p6spy:p6spy', 'bintray.version': project.version.toString() ]
        }
    }
}

// to publish to bintray and later sync to maven-central
bintray {
  user = System.getenv('BINTRAY_USER')
  key = System.getenv('BINTRAY_API_KEY')
  publications = ['maven']
  // dryRun = true
  // publish = true
  pkg {
    repo = 'maven'
    name = 'p6spy:p6spy'
    userOrg = group
    desc = description
    websiteUrl = 'https://github.com/p6spy/p6spy'
    issueTrackerUrl = 'https://github.com/p6spy/p6spy/issues'
    vcsUrl = 'https://github.com/p6spy/p6spy.git'
    licenses = ['Apache-2.0']
    publicDownloadNumbers = true
    githubRepo = 'p6spy/p6spy'
    githubReleaseNotesFile = 'docs/releasenotes.md'
    version {
      released = new Date()
      name = project.version
      vcsTag = "p6spy-${project.version}"

      // Optional configuration for Maven Central sync of the version
      mavenCentralSync {
          sync = true //[Default: true] Determines whether to sync the version to Maven Central.
          close = '1' //Optional property. By default the staging repository is closed and artifacts are released to Maven Central. You can optionally turn this behaviour off (by puting 0 as value) and release the version manually.
          user = System.getenv('SONATYPE_USERNAME') //OSS user token: mandatory
          password = System.getenv('SONATYPE_PASSWORD') //OSS user password: mandatory
      }
    }
  }
}

更新

发布:


谢谢Peter!这确实很混乱,我不再为自己的困惑感到难过 :) 我很高兴有人已经解决了这个问题。 - Steve Ebersole
如果您不介意的话,能否分享一下您使用Bintray的经验?我非常担心似乎很难得到帮助。我们正在决定使用Bintray还是Sonatype的OSSRH。我非常喜欢Bintray,但这种似乎难以获得帮助的情况确实令人担忧。谢谢!https://hibernate.atlassian.net/browse/HHH-12172 - Steve Ebersole
说实话,我的记忆力真的很差,在一分钟前检查了 travis.yml 后,我发现只有一个插件用于发布到 oss.jfrog.org,另一个插件则用于 bintray 相关的活动。对于造成的困惑,我感到抱歉。我已经更新了答案。 - Peter Butkovic
顺便提一下,在 Hibernate JIRA 上也进行了评论。 - Peter Butkovic

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接