gilcloud / sbt-gitlab

sbt plugin to allow dependency resolution and artifact publishing for gitlab
Apache License 2.0
26 stars 19 forks source link

GitLab now supports sbt natively #41

Open matejcerny opened 6 months ago

matejcerny commented 6 months ago

For all the developers outhere, GitLab now supports sbt push/pull natively, see: https://gitlab.com/gitlab-org/gitlab/-/issues/408479

object Registry {
  val credentials: Credentials = sys.env
    .get("CI_JOB_TOKEN") // automatically generated token in the gitlab-ci
    .map(Credentials("GitLab Packages Registry", "gitlab.com", "gitlab-ci-token", _))
    .getOrElse(Credentials(Path.userHome / ".sbt" / ".credentials")) // for local development

  val additionalResolvers: Seq[MavenRepository] = Seq(
    "GitLab" at
      "https://gitlab.com/api/v4/projects/<PROJECT_ID>/packages/maven"
  )

  def publishToGitlab(projectId: Int): Option[MavenRepository] =
    Some("gitlab" at s"https://gitlab.com/api/v4/projects/$projectId/packages/maven")
}

build.sbt:

ThisBuild / resolvers ++= Registry.additionalResolvers
ThisBuild / credentials += Registry.credentials
ThisBuild / publishTo := Registry.publishToGitlab(37794088) // Gitlab project id

.sbt/.credentials:

realm=GitLab Packages Registry
host=gitlab.com
user=Private-Token
password=<YOUR-TOKEN>
thereisnospoon commented 4 months ago

Does this work for self-hosted Gitlab instances though? We were not able to use this in such case so we use the plugin instead.