How to Publish a Jitpack Library for a Private Repository

How to Publish a Jitpack Library for a Private Repository

I've noticed a common trend where most tutorials focus on using public repositories for library distribution. This inspired me to craft a guide specifically for those looking to publish a Jitpack library using a private repository. Here's a step-by-step breakdown:

1. Releasing Your Code

  • Navigate to your GitHub repository.

  • On the right sidebar, locate and click on the "Releases" section.

  • Choose to create a new tag, then finalize it by creating a release.

2. Setting Up Jitpack for Private Repositories

  • Access Jitpack's private repository connection page via this link.

  • In the upper-right corner, find and click on "Sign in to GitHub" for authorization, then allow Jitpack access.

3. Generating an Authentication Token

  • Click the gear icon on the Jitpack page under Lookup button

  • Enter your GitHub username in the "Lookup" field to generate a token.

  • Copy this token for later use in your project.

4. Integrating with Your Project

To utilize Jitpack with your private repository, follow these steps:

  • Step 1: Authorize Jitpack by obtaining your personal access token.

  • Step 2: Append your token to your gradle.properties file:

      authToken=jp_45rmcjigd3ldpqt1imk7a5dhnm
    
  • Step 3: Configure your project's dependency resolution:

      dependencyResolutionManagement {
          repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
          repositories {
              ...
              maven {
                  url "https://jitpack.io"
                  credentials { username authToken }
              }
          }
      }
    

5. Locating Your Repository on Jitpack

  • Return to the Jitpack page and enter your repository's URL.

  • Click on "Lookup" to find your repository.

6. Using Your Private Library

After configuration, you can install any of your private libraries by:

repositories {
    maven {
        url "https://jitpack.io"
        credentials { username authToken }  // Use the generated token from Jitpack
    }
}
dependencies {
    compile 'com.github.User:PrivateRepo:Tag'
}

By following these steps, you can securely publish and use your libraries from private repositories with Jitpack.