arsalandywriter.com

How to Publish a Kotlin Multiplatform Library on GitHub Packages

Written on

Publishing a library within the open-source community can be an exciting venture. GitHub serves as a pivotal platform for code collaboration and sharing, and its feature, GitHub Packages, simplifies the process of managing and hosting software packages. If you have developed an impressive library and wish to make it accessible to others, this guide will lead you through the process of publishing it on GitHub Packages.

We choose GitHub Packages for its ease of setup and no associated costs.

Step 1: Create Your GitHub Repository

Before you can publish your Kotlin Multiplatform (KMP) library, you need to have a dedicated repository on GitHub. If you haven’t created one yet, start by clicking the “+” icon on the GitHub homepage and selecting “New repository.” Assign a descriptive name, add relevant details, and initialize it with a README if necessary.

Step 2: Prepare Your Library for Packaging

Ensure that your library is organized and includes all the files needed for distribution. This means having your source code, documentation, and any other important resources. A clear README file is essential, as it will be the first point of reference for potential users.

Step 3: Create an Access Token

To publish packages on GitHub, you must authenticate your account. This is done by generating a personal access token. Go to your GitHub account settings, navigate to “Developer settings,” then “Personal access tokens.” Create a new token with permissions that allow for reading and writing to packages. Copy this token for use in the upcoming steps.

Path to Access Token Creation: Account Settings > Developer Settings > Personal Access Token > Tokens > Generate New Token

Step 4: Publish Your Library

With your repository established, necessary metadata in place, and authentication sorted, it’s time to publish your library to GitHub Packages.

In your gradle.properties file, include your Maven username and password:

In build.gradle.kts, add the following:

Note: - We utilize BasicAuthentication as our authentication method. - The PasswordCredentials::class uses the mavenUsername and mavenPassword for authentication.

It’s advisable to store these credentials in a separate file and add it to your .gitignore to prevent accidental commits to your repository.

Additionally, include it at the root level of your build.gradle.kts:

Make sure to add this configuration for publishing your library:

For build.gradle.kts in the androidApp module:

And for build.gradle.kts in the shared module:

Finally, open your terminal and execute the following command:

You should see a confirmation of the successful operation:

Step 5: Verification

Once your library is successfully published, check the GitHub Packages page for your repository to confirm that your package appears there. This allows users to find, install, and integrate your library into their projects seamlessly.

Now you can utilize your packages:

In settings.gradle.kts:

In build.gradle.kts for androidApp:

In build.gradle.kts for shared:

You’re now ready to enjoy the capabilities of your published packages!

Share the page:

Twitter Facebook Reddit LinkIn

-----------------------

Recent Post:

Understanding Nuclear Power Plants: A Comprehensive Overview

Explore how nuclear power plants convert atomic energy into electricity through fission and thermal processes.

Do I Really Want 44 Billion Dollars? Rethinking Wealth

Reflecting on wealth and its impact on personal growth, I explore what I'd do with a windfall and the importance of giving back.

Chinese Rocket Debris Falls: Where Did It Land?

A 23-ton Chinese rocket fragment fell to Earth, but where? Discover the details of this incident and the implications for space safety.

How to Resolve the 'Invalid React Child' Error Effectively

Learn how to resolve the 'Objects are not valid as a React child' error in your React applications with effective solutions.

Prioritizing Health: A Commitment for Ourselves and Others

This article emphasizes the necessity of prioritizing personal health to better support loved ones and fulfill responsibilities.

Confidence Building Strategies for Your 20s: A Personal Journey

Explore effective strategies to enhance your confidence in your 20s through personal experiences and practical tips.

Mastering PDF Management in Python: A Detailed Exploration

A comprehensive guide on processing PDFs with Python, covering everything from data extraction to advanced PDF operations.

Best Practices for Protocol Buffers: Naming and Organization

Explore essential naming conventions and organizational strategies for Protocol Buffers to enhance maintainability and readability.