Gradle: Bintray tutorial

We can use gradle to upload our project as a maven repository to bintray, and by extension jcenter and mavenCentral.

Sign up to at Create a repository, let's say we call it wonderful.

Now let's create the build.gradle file giving a buildscript repository, adding the bintray plugin, and applying the java, maven and maven-publish plugins.

buildscript {
  repositories {

plugins {
  id "com.jfrog.bintray" version "1.7"

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'

Now let's add the standard version, archivesBaseName, group and description. We'll reference this as project.version etc later on.

archivesBaseName = 'jersey-json-wadl'
group = 'com.newfivefour'
version = '0.0.1'
description = 'Something, innit'

The maven-publish plugin allows us to define a publishing.publications maven block. This defines what we're publishing (java components), the groupId, the artifactId and the version. The publication is called MyPublication.

publishing {
  publications {
      MyPublication(MavenPublication) {
          groupId =
          artifactId = project.archivesBaseName
          version = project.version

Now let's create the bintray block. We get our bintray user and api key from the system environment, and we reference the name of the publication created above, and we tell bintray to publish the artifact, instead of holding it on bintray waiting for us to press 'publish'.

bintray {
    user = System.getenv('BINTRAY_USER')
    key = System.getenv('BINTRAY_KEY')
    publications = ['MyPublication']
    publish = true
    pkg ...

The pkg part is where things get interesting:

    pkg {
        repo = 'wondeful'
        name = 'somerandomname'
        licenses = ['Apache-2.0']
        vcsUrl = ''
        version {
            name = project.version
            desc = project.description
            released  = new Date()

We define the repo name we created on bintray. We give it a name, or a package as it will appear on the bintray UI. We also specify the licence and VCS url. The version block reuses the version, desc from our project and we set the release date to now.

Running ./gradlew --no-daemon bintrayUpload (we're using --no-daemon since the daemon is buggy and keeps old values) will upload our repository. Wait a few seconds, and our maven repository should start to appear at You should see in the bintray web interface, too.

Now, in another gradle project, if you define a repository via maven { url "" } you can call a dependency called compile 'com.newfivefour:jersey-json-wadl:0.0.1'.

gradle gradle-bintray

Edit on github
comments powered by Disqus
Click me