Publishing an Android Library to Maven Central With Gradle
I recently migrated the We Heart It Android app project to Android Studio and I thought I’d migrate the Android-ImageManager library into the new format as well. That was the easy part. Another thing I wanted to do was to upload it to Maven Central, so it would make people’s lives easier when using it.
Ok this was painful. Here are the steps I took in order to achieve it, so hopefully people won’t struggle that much doing it in the future:
- Follow Chris Banes’ steps;
- Follow the steps here to configure the upload username and password;
- Make sure you edit
build.gradlewith your library’s information (version, description, links, etc);
- Follow this guide. To summarize, you’ll need to create a Sonatype JIRA account and then you’ll have to create an issue there in order to create your project. That is basically apply for open source project hosting (that’s basically the steps 2 and 3 on the user guide mentioned above);
- Wait for your issue to be “Resolved”, that may take up to 2 business days (!!!). Someone from Sonatype will do it and you’ll get an email;
./gradlew clean build uploadArchivesto build and upload your project into Sonatype. IMPORTANT: You have to upload a Debug build first, otherwise it is not gonna work. You do that by adding
-SNAPSHOTat the end of your
gradle.properties, like this, eg.:
- After that, if all went well, you should see your project here. You can navigate through the folders. My project’s group id was
com.felipecsl.android, so I could find it at http://oss.sonatype.org/content/repositories/snapshots/com/felipecsl/android/
I still havent figured out how to promote a Staging Repository. Right now it is failing to close the repository since the package is not signed. I will update this post once I have a solution.
In the meantime, you can already use your snapshot with Maven/Gradle.
Here is how your
build.gradle would look like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Well that is pretty much it for now. It took me almost an entire afternoon to figure this all out, hope it is useful for other people. If you’re interested in a simpler and a lot more elegant solution for Open Source library project hosting, check rubygems.org which is used to, guess what, host Ruby gems. That is really piece of cake compared to all this Java mess :sigh: