At the end of this guide, I’ll have you publishing code to Maven Central and jCenter so other people can start using your code like so:

build.gradle

compile 'com.yourname:helloworld:1.0.0' // Add your package

Test.java

import com.yourname.helloworld.Hello; // Import your package String s = new Hello().getGreeting(); // "Hello World!"

Sound good? Let’s go.

Step 1. Sign up for Sonatype JIRA account.

Step 2. Sign up for Bintray and add your Sonatype username to https://bintray.com/profile/edit

Step 3. Clone my project on GitHub. (It’s a simple helloworld project with necessary gradle files / plugins)

This project has two important files: build.gradle and deploy.gradle. The deploy.gradle file you should be able to copy as-is over to your existing projects and use alongside the configuration you set in your build.gradle which is described below. For simplicity, I’ll assume you just work from my sample repo you just cloned.

Step 4. Edit the build.gradle file to your liking.



version ‘1.0.0’ // The package version.

ext {

pkgName = ‘helloworld’ // Unique package name. I'm creative.

pkgDesc = ‘Hello world sample library’

githubRepo = ‘github.com/ryanseys/helloworld-java’

pkgLicense = ‘Apache-2.0’

pkgLicenseUrl = ‘

devInfo = {

id ‘ryanseys’

name ‘Ryan Seys’

url ‘

email ‘

}

bintrayUser = System.getenv(‘BINTRAY_USER’)

bintrayKey = System.getenv(‘BINTRAY_API_KEY’)

mavenUserToken = System.getenv(‘MAVEN_USER_TOKEN’)

mavenUserPass = System.getenv(‘MAVEN_USER_PASS’)

deployDryRun = false // Set to true to not deploy on run.

} group ‘com.ryanseys’ // Reverse URL unique group id. Edit me!version ‘1.0.0’ // The package version.ext {pkgName = ‘helloworld’ // Unique package name. I'm creative.pkgDesc = ‘Hello world sample library’githubRepo = ‘github.com/ryanseys/helloworld-java’pkgLicense = ‘Apache-2.0’pkgLicenseUrl = ‘ http://www.apache.org/licenses/LICENSE-2.0.txt' devInfo = {id ‘ryanseys’name ‘Ryan Seys’url ‘ https://github.com/ryanseys' email ‘ ryan@ryanseys.com bintrayUser = System.getenv(‘BINTRAY_USER’)bintrayKey = System.getenv(‘BINTRAY_API_KEY’)mavenUserToken = System.getenv(‘MAVEN_USER_TOKEN’)mavenUserPass = System.getenv(‘MAVEN_USER_PASS’)deployDryRun = false // Set to true to not deploy on run.

Step 5. Set up environment variables for auth tokens.

Go to https://bintray.com/profile/edit and click API Key on the left table. Drop your information into your .bashrc or .zshrc file.

export BINTRAY_USER=your_bintray_username

export BINTRAY_API_KEY=your_api_key

Sign into https://oss.sonatype.org/ with your original Sonatype JIRA credentials and under the Profile tab, click on “User Token” in the drop-down menu then click on “Access User Token”. It should look something like this:

Get a user token and password (these are both different from the one you signed in with) and put them in your environment variables too.

export MAVEN_USER_TOKEN=your_sonatype_user_token

export MAVEN_USER_PASS=your_sonatype_token_password

Step 6. Publish!

In the project root, run the following to build and upload everything:

./gradlew bintrayUpload

You did it! Almost.

Step 7. Finishing up

Sign in to https://bintray.com/ to see how you did. If this is your first deploy of the package then you’ll have to send a message to get approved for that package name. A message should pop up on the site explaining how to go about sending that request. Approval for this should take less than a couple hours. Why it’s not instant and automated? No clue. I know, I said no bullshit, I’m sorry.

The easiest way to see if you did the right thing is to try importing your package into another project like shown at the very beginning of this post.

File a bug if you couldn’t get it to work. Happy publishing!