Confused about process to publish snapshots to BinTray
Asked Answered
D

1

6

I want to investigate publishing Hibernate ORM jars to Bintray. However one requirement we have is to be able to publish snapshots, which I see Bintray now supports through this OJO repository. However, I am quite confused about how this is supposed to work after reading the documentation.

First, the documentation mentions that I should be able to request publishing to JCenter and at the same time be able to request to be able to publish snapshots. However, I see no such options: https://bintray.com/hibernate/artifacts/hibernate-orm

Secondly, after I get the account on OJO set up, what, if anything, do I need to do special with the Bintray/Gradle plugin?

Dermatome answered 18/12, 2017 at 16:0 Comment(1)
FWIW this has been an open question/issue on the bintray gradle plugin for 6 months: github.com/bintray/gradle-bintray-plugin/issues/191Dermatome
C
6

After many trial and errors I've ended up with the following setup.

We use 2 different plugins for publishing:

  • snapshots and release publishing (using com.jfrog.artifactory) and
  • bintray-related activities (using com.jfrog.bintray) in gradle (in the project p6spy).

Relevant parts from the build.gradle file follow, please note the specifics of the project :

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 '[email protected]'
                }
                builder.developer {
                  builder.name 'Peter Butkovic'
                  builder.email '[email protected]'
                }
                builder.developer {
                  builder.name 'Felix Barnsteiner'
                  builder.email '[email protected]'
                }
            }

            // 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
      }
    }
  }
}

UPDATE

Published:

Caen answered 19/12, 2017 at 13:51 Comment(4)
Thanks Peter! That is indeed messy and I no longer feel bad about my confusion :) I'm very glad someone already figured this out.Dermatome
If you don't mind, would you be willing to share your experience with using Bintray? I am very nervous that it seems quite difficult to get help. We are trying to decide between Bintray and Sonatype's OSSRH. I very much prefer Bintray, but this seeming difficulty getting help is a definite concern. Thanks! hibernate.atlassian.net/browse/HHH-12172Dermatome
well, to be honest, my memory is really bad and after inspecting the travis.yml a minute ago, I've found out only 1 plugin is used for publishing to oss.jfrog.org, the other one does bintray-related activities. Sorry for confusion. I updated the answer.Caen
btw. commented in hibernate jira as wellCaen

© 2022 - 2024 — McMap. All rights reserved.