Scala Packages Hosted With Github
April 17, 2023

Scala Packages Hosted With Github

Posted on April 17, 2023

If you want Github to host your Scala packages in a public Maven repository, it basically four easy steps. I have an example repo at https://github.com/kyledinh/scala-library, but it’s …

Basically:

  1. Get token from GitHub
  2. Apply to SBT settings for SBT plugin
  3. compile and publish
  4. Usage package in your other project, add it you your build.sbt



Get token from GitHub

  • Generate a token for GitHub, navigate to Settings > Developer Settings > Personal access token > Token (classic) > “Generate new token” button
  • Select the permission options
  • Select how long this token will be vaild before having to generate a new one

GitHub Settings

Add GitHub token to your credentials

  • Add your new Credentials to this file: $HOME/.sbt/1.0/github.sbt
credentials += 
  Credentials(
    "GitHub Package Registry",
    "maven.pkg.github.com",
    "GITHUB USERNAME",
    "GITHUB TOKEN")

Install the SBTplugin

Publish a package to GitHub Maven

  • sbtn publish

Use your Scala package in other projects

  • build.sbt, use an externalResolvers to look at your package on GitHub
externalResolvers += "ScalaLibrary packages" at "https://maven.pkg.github.com/kyledinh/scala-library"

lazy val root = project
  .in(file("."))
  .settings(
    name                                   := "scala-3-workspace",
    version                                := "0.1.0-SNAPSHOT",
    scalaVersion                           := "3.2.2",
    libraryDependencies += "org.scalameta" %% "munit" % "0.7.29" % Test,
    libraryDependencies += "com.kyledinh" %% "scala-library_3" % "0.1.0-SNAPSHOT"
  )

That’s it, Folks!




References

I learned from this article, by Manuel Rodriguez: [https://medium.com/@supermanue/how-to-publish-a-scala-library-in-github-bfb0fa39c1e4](https://medium.com/@supermanue/how-to-publish-a-scala-library-in-github-bfb0fa39c1e4), then updated to the current Scala3, SBT plugin and verison.