MindOrks
Published in

MindOrks

Distribute multiple-module library on Bintray for Java and Android developers

Subscribe to the latest blog posts and projects.

DEPRECATED

Bintray just stopped accepting new packages from early 2021. Therefore, to host your Java/Library, you can use Maven Central (Sonatype) by following this post.

Scenario

Before jumping into technical stuff, I would like to share our story.

Image credit: https://goo.gl/f7K38c

We planned to build a world-class manga(漫画) studio. Our software team firstly created a manga module that serves as a primary library and it is written purely in Java.

After that, we utilize it to produce concrete mangas. Our first masterpiece is Doraemon , and our partners would like to integrate it into their Android apps. So, we developed Android doraemon module which extends manga features.

After hard working hours, our products were ready to be delivered to our partners. Because Java and Android developers use Maven repository, so we decide to release all of the mangas on jCenter (one of the popular Maven repository hosts). The process is described as the following diagram.

Problem

It has been a while since I published an article about Android library distribution which introduces Maven repository and necessary steps to distribute your library using the Bintray platform. We can follow these steps described in that previous article.

However, our manga studio is growing quickly, and we plan to produce 2 mangas every day. So, we need to find out how to distribute hundreds or thousands of mangas in an easier and more effortless way.

And the last Gradle configuration fits with one module release only.

For a while, I found that there are a lot of libraries out there in the same situation.

Let’s take Retrofit library as an example, you definitely saw multiple modules involved such as retrofit , retrofit-adapters , retrofit-converters. From a library user view, when integrating Retrofit in our apps, we must add its core module via Gradle dependence.

compile ‘com.squareup.retrofit2:retrofit:2.3.0’

Other modules are optional based on our need for specific apps.

// Adapters
com.squareup.retrofit2:adapter-rxjava2
com.squareup.retrofit2:adapter-guava
com.squareup.retrofit2:adapter-java8
// Converters
com.squareup.retrofit2:converter-gson
com.squareup.retrofit2:converter-moshi
….

All modules are put in the same project in development but released in different packages on Maven. You can check them out here core Retrofit, RxJava adapter, Gson converter, and so on.

Finally, we found our own way to achieve this goal. In the following part, I would like to introduce a simple way to distribute a multiple-module library on Bintray with a detailed explanation and fully source-code sample.

Steps

Please go through the following steps if you would like to distribute your library.

  1. Grab Gradle’s files which help you to build and upload libraries on Bintray here. It is similar to Gradle files you saw in my previous article but small changes. Put them inside /jcenter/ folder as in the sample.
  2. We need a common configuration Gradle file I named release-bintray.gradle .
  3. For each module, let’s create its own gradle.properties and declare its specific configuration details.
  4. In the module’s build.gradle file, put this line at the bottom to let Gradle know to run it when you call the Bintray upload task.
    apply from: rootProject.file(‘release-bintray.gradle’)
    Sample file.
  5. Almost done, make sure you put your Bintray account credentials inside local.properties file as following (this file is ignored by Git, not be uploaded on version control hosting).
    bintray.user=your_username
    bintray.apikey=your_api_key (i.e: adfasdf342342j34lba84a25f8c3)
    bintray.gpg.password=your_gpg_password
  6. Let’s run Gradle task with one command. ./gradlew bintrayUpload
  7. Tell other developers to integrate your new awesome library.

For full source codes, please check the sample on Github.

And our two modules are now successfully released into separate packages, manga and doraemon, on Bintray as expected.

Note: The story of building world-class manga studio is just in my imagination, therefore please don’t wait for any more-than-a-stupid-sample masterpiece coming out.

If you are interested in my new blog posts and projects, you can subscribe to my newsletter by clicking the below link.

Subscribe to the latest blog posts and projects.

Or please get in touch with me via Github, Twitter, Facebook, or LinkedIn. Happy coding and have a good time!

--

--

--

Our community publishes stories worth reading on Android Development

Recommended from Medium

eLearning Software Solutions & Content Outsourcing

How we Made a Community & E-Learning Platform using MERN Stack

Laravel with Packages | Laravel 9 QR Code Generator Example

Cloud DevOps and air flight — Shipping continuously and reliably with feature flags and…

Important Questions That Clients May Ask Dedicated Mobile App Developers

Python in 7 Days — 07/7:Exceptions & How to Handle Then

Introduction to NP Completeness

Guide: Using Simpli Finance Farm

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Quang Nguyen

Quang Nguyen

Software engineer and designer, specializing in native mobile apps, currently building digital scent technology at aromajoin.com.

More from Medium

Android Stack Weekly— Issue #2

Why Jetpack Compose for Android Development?

Android — Text View

Introducing Android 12