scalasbt

GitHub Actions Not Resolving GitHub Packages via Sbt Plugin


I have a project where I build a sbt settings plugin that I intend to use across all my other projects. In this sbt plugin project, I define several common settings like resolvers, scm info, other static settings.

I then publish this setting to my organizations package in GitHub and I can even see it being available as shown here: https://github.com/orgs/open-electrons/packages

I then use this sbt settings plugin in my other projects by adding it like this in the plugins.sbt project like this:

addSbtPlugin("com.openelectrons" % "openelectrons-sbt-settings" % "0.0.1")

When I run this project (say Project A) which has this build.sbt:

import SharedSettings._

lazy val commonSettings = SharedSettings.settings

// Build definition for the ocpp-gateway-server project
lazy val ocppGatewayServer = (project in file("."))
  .enablePlugins(PlayScala, DockerPlugin)
  .settings(
    commonSettings,
    ....
    ....

The SharedSettings come from the sbt settings plugin that is available in the GitHub packages. I then include all those settings in this project like above. The SharedSettings actually contain the resolvers defined like this:

  // Dependency resolvers
  val sharedResolvers: Seq[Resolver] = Seq(
    Resolver.mavenCentral,
    "Typesafe Releases" at "https://repo.typesafe.com/typesafe/releases/",
    "Typesafe Snapshots" at "https://repo.typesafe.com/typesafe/snapshots/",
    "GitHub Packages" at "https://maven.pkg.github.com/open-electrons/open-electrons-templates"
  ) ++ Resolver.sonatypeOssRepos("snapshots") ++ Resolver.sonatypeOssRepos("releases")

When I run my Project A, I cannot see that the GitHub Packages is even resolved. The build looks for the openelectrons-sbt-settings dependency in repo1 and in these 3 locations:

[error]   not found: https://repo1.maven.org/maven2/com/openelectrons/openelectrons-sbt-settings_2.12_1.0/0.0.1/openelectrons-sbt-settings-0.0.1.pom
[error]   not found: /home/runner/.ivy2/localcom.openelectrons/openelectrons-sbt-settings/scala_2.12/sbt_1.0/0.0.1/ivys/ivy.xml
[error]   not found: https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.openelectrons/openelectrons-sbt-settings/scala_2.12/sbt_1.0/0.0.1/ivys/ivy.xml
[error]   not found: https://repo.typesafe.com/typesafe/ivy-releases/com.openelectrons/openelectrons-sbt-settings/scala_2.12/sbt_1.0/0.0.1/ivys/ivy.xml

I do not see any log lines where it tried to download it from GitHub Packages. How do I fix this?


Solution

  • I believe that for the plugin to be found, the resolvers need to be overridden in the plugins.sbt file itself (this is probably what was mentioned in a comment: if you put the resolver for the plugin in the plugin itself, you are creating a bootstrapping problem).

    Try this:

    resolvers += "GitHub Packages" at "https://maven.pkg.github.com/open-electrons/open-electrons-templates"
    
    addSbtPlugin("com.openelectrons" % "openelectrons-sbt-settings" % "0.0.1")