gilcloud / sbt-gitlab   0.1.2

Apache License 2.0 GitHub

sbt plugin to allow dependency resolution and artifact publishing for gitlab

Scala versions: 2.12
sbt plugins: 1.x

sbt-gitlab

Gitlab dependency resolution and artifact publishing for sbt

addSbtPlugin("com.gilcloud" % "sbt-gitlab" % "0.1.2") // in your project/plugins.sbt file

Usage

This plugin requires sbt 1.3.0+ as it relies on sbt.internal.CustomHTTP

Dependency Resolution

This plugin also supports dependency resolution from private gitlab package repositories, to use this you need to switch to ivy for dependency resolution rather than the now default coursier as this plugin overrides the handler for ivy. This can be done for example by adding.

ThisBuild / useCoursier := false

Publishing to Gitlab via Gitlab CI/CD

Utilizing the sbt publish command within GitLab CI/CD should require no additional configuration. This plugin automatically pulls the following GitLab environment variables which should always be provided by default within GitLab Pipelines

$CI_JOB_TOKEN   # Access Token to authorize read/writes to the gitlab pakcage registry
$CI_PROJECT_ID  # Project ID for active project pipeline. Used so Gitlab knows what project to publish the artifact under
$CI_GROUP_ID    # Gitlab Groupt ID. Used for fetching Artifacts published under the specified Group.
                # In a pipeline this would be set to the id of the group the project is under (when applicable)
$CI_SERVER_HOST # The host name for gitlab defaults to gitlab.com

Any of these 'defaults' can be overwritten in your build.sbt file

import com.gilcloud.sbt.gitlab.{GitlabCredentials,GitlabPlugin}

GitlabPlugin.autoImport.gitlabGroupId     :=  Some(12345)
GitlabPlugin.autoImport.gitlabProjectId   :=  Some(12345)
GitlabPlugin.autoImport.gitlabDomain      :=  "my-gitlab-host.com"
GitlabPlugin.autoImport.gitlabCredentials :=  Some(GitlabCredentials("Private-Token","<API-KEY>"))

// Alternatively for credential managment
// ideal for pulling artifacts locally and keeping tokens out of your source control
// see below for sample .credentials file
credentials += Credentials(Path.userHome / ".sbt" / ".credentials.gitlab"),

~/.sbt/.credentials.gitlab

realm=gitlab
host=my-git-lab-host
user=Private-Token
password=<API-KEY>

Testing

Run test for regular unit tests.

Run scripted for sbt script tests.

Publishing

  1. publish your source to GitHub
  2. create a bintray account and set up bintray credentials
  3. create a bintray repository sbt-plugins
  4. update your bintray publishing settings in build.sbt
  5. sbt publish
  6. request inclusion in sbt-plugin-releases
  7. Add your plugin to the community plugins list
  8. Claim your project an Scaladex