Skip to content

Instantly share code, notes, and snippets.

@guizmaii
Forked from davideicardi/README.md
Created July 1, 2021 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guizmaii/2ca47b74ad8e26c772d7df6ada8ddb00 to your computer and use it in GitHub Desktop.
Save guizmaii/2ca47b74ad8e26c772d7df6ada8ddb00 to your computer and use it in GitHub Desktop.
Publish Maven library to Github packages with SBT and github actions

Publish

Add the following configuration to your build.sbt:

  // publish to github packages settings
  publishTo := Some("GitHub <GITHUB_OWNER> Apache Maven Packages" at "https://maven.pkg.github.com/<GITHUB_OWNER>/<GITHUB_PROJECT>"),
  publishMavenStyle := true,
  credentials += Credentials(
    "GitHub Package Registry",
    "maven.pkg.github.com",
    "<GITHUB_OWNER>",
    System.getenv("GITHUB_TOKEN")
  ),

Set the GITHUB_TOKEN environment variable to a valid github personal access token with write package permissions.

Create a workflow inside .github/workflows/publish.yml

name: Publish package to GitHub Packages
on:
  release:
    types: [created]

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8
    - name: Publish package
      run: sbt test publish
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Usage

Set the GITHUB_TOKEN environment variable to a valid github personal access token.

externalResolvers += "GitHub davideicardi Apache Maven Packages" at "https://maven.pkg.github.com/davideicardi/kaa"
libraryDependencies += "com.davideicardi" %% "kaa" % "<version>"
credentials += Credentials(
    "GitHub Package Registry",
    "maven.pkg.github.com",
    "<GITHUB_OWNER>",
    System.getenv("GITHUB_TOKEN")
  )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment