Quick and Dirty Guide to Publishing an Android Library with Maven-Publish

Carter Hudson
1 min readJun 26, 2022

--

These days, you have to use the maven-publish plugin to publish your Android library to a repository, even if you just want to use jitpack.

  • The documentation is protracted and ambiguous.
  • ./gradlew publishToMavenLocal doesn’t publish to ~/<USER_HOME>/.m2/repositories by default

For my own edification in the future, here’s a barebones example of exactly what worked for me:

android {
...

publishing {
singleVariant('release')
}
...
}
publishing {
publications {
release(MavenPublication) {
groupId 'com.example'
artifactId 'artifactId'
version = android.defaultConfig.versionName

afterEvaluate {
from components.release
}
}
}
}

Jitpack was also angry about the Android Library Plugin version I was using, so watch out for that as well.

Maven local builds will appear in your library’s build folder unless you change the directory in the publications block. The following should work:

publishing {
publications {
...
}
repositories {
mavenLocal()
}
}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response