如何更新已发布至Maven Central的Android库?
Hey there! Since you’ve already successfully published your Android library to Maven Central before, updating it is just a simplified repeat of those initial steps. Here’s a step-by-step breakdown tailored to your workflow:
Step 1: Update Your Library Version Number
First, you need to increment your library’s version to a unique value (Maven Central doesn’t allow overwriting existing versions). Head to your module’s build.gradle (or build.gradle.kts) file and update the versionName field. For example:
// Old version versionName "1.0.0" // Updated version (follow semantic versioning for clarity) versionName "1.0.1" // bug fix update // OR versionName "1.1.0" // feature update
Make sure this version hasn’t been used before—double-check Maven Central if you’re unsure.
Step 2: Finalize and Test Your Updated Code
Before uploading, confirm all your code changes (bug fixes, new features, etc.) are complete, tested, and free of compilation errors. Sync your Gradle project to ensure everything is in order.
Step 3: Upload the Updated Library Using Gradle
Run the same uploadArchives Gradle task you used for your initial publish. You can do this via:
- Android Studio’s Gradle sidebar: Navigate to your library module > Tasks > upload > uploadArchives
- Command line: Execute
./gradlew :your-library-module:uploadArchives(replaceyour-library-modulewith your actual module name)
If you’ve migrated to newer Android Gradle Plugin (AGP) versions (7.0+), you might be using the publish task instead—run ./gradlew :your-library-module:publish in that case.
Step 4: Close and Release the New Version in Nexus Repository Manager
- Log in to the Sonatype Nexus Repository Manager using your existing account.
- Navigate to the Staging Repositories section—you’ll see a new entry for your updated library version.
- Select the new staging repository and click Close. This triggers Maven Central’s validation checks (e.g., verifying signatures, valid POM files). Wait for the validation to complete (this might take a few minutes).
- Once the close operation succeeds, select the repository again and click Release. This pushes your updated library to Maven Central.
Step 5: Wait for Synchronization
Just like your initial publish, it can take a few hours for the updated version to appear in Maven Central’s search index and be available for users to pull into their projects.
Quick Notes to Avoid Issues
- Ensure you’re using the same groupId and artifactId as your original library—changing these would create a new separate library instead of updating the existing one.
- Keep your signing configuration intact—Maven Central requires signed artifacts, so if your keystore or signing setup has changed, update your Gradle config accordingly before uploading.
- Stick to semantic versioning (SemVer) to help users understand the scope of your update (patch, minor, major changes).
内容的提问来源于stack exchange,提问作者Rachit

