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:

Exploring the Future of ChatGPT: 6 Transformative Insights

Delving into six transformative ideas about ChatGPT and its long-term implications for content creation and society.

Self-Forgiveness: A Journey Towards Better Mental Well-Being

Explore self-forgiveness as a vital step toward improving mental health and letting go of past mistakes.

Overcoming Life's Hurdles: The Key to Elevating Self-Image

Discover how enhancing your self-image can transform obstacles into opportunities for growth and resilience.

Transform Your Life with These Five Simple Habits Today

Discover five easy habits to integrate into your daily routine for lasting change and enhanced well-being.

Mastering Sales: 7 Essential Strategies for Handling Rejections

Discover seven effective techniques to handle rejection in sales and turn

Unlocking the Keys to a Meaningful Life: Goals, Self-Discovery, and Positivity

Explore how goal-setting and self-discovery can enhance your life, creating a path toward fulfillment and positivity.

Innovative Solar Solutions: Space-Based Power for a Greener Future

Exploring space-based solar power as a sustainable energy solution for the future.

Exploring Philosophical Perspectives on War and Peace

A look at historical philosophical views on war and peace and their implications for society today, highlighting key thinkers and their contributions.