Reputation: 1374
I'm having problems setting up Leiningen to resolve private dependencies from GitLab.
It works well in Maven projects. I configured it by providing configuration with HTTP header (Private-Token:abcd
) that is stored in the ~/.m2/settings.xml
(as described in the GitLab docs).
I've tried setting something similar with lein by following the docs, but it always fails on resolving the dependency printing Could not find artifact ... in releases
. Here is what I added to project.clj:
:repositories [["releases" {:url "https://gitlab.com/api/v4/projects/.../packages/maven"
:creds :gpg}]]
I'm probably adding the private token incorrectly (or using wrong credentials provider). Tried different combinations of username/password/passhprase added to ~/.lein/credentials.clj (and later encrypted with gpg), but nothing worked correctly. Any hints?
Upvotes: 3
Views: 306
Reputation: 573
According to gitlab's authentication with registry docs the authentication is performed using access tokens, which, according to this gitlab doc, can either be passed in the private_token
url query parameter or the PRIVATE-TOKEN
header.
Unfortunately, Leiningen does not allow either of those authentication methods. But, fortunately, there's a plugin for it. The plugin is really just a tiny piece of code which represents what is called a "wagon" factory.
You use it like so:
;; inside project.clj file
;; "your-lib" is the name of the package you published to to your gitlab's package registry
:dependencies [[your-lib "0.1.0"]]
;; group and name of the package are usually the same,
;; so you can mention just one of them
;; and it will be expanded to look like this:
;; your-lib/your-lib/0.1.0/your-lib-0.1.0.jar
:plugins [[net.clojars.hissyfit/lein-gitlab-cart "1.0.0"]]
:repositories [["whatever-repo-label" {:url "gitlab://<your_gitlab_domain>/api/v4/projects/<your_project_id>/packages/maven"
:username "Private-Token"
:password <token_value_here>}]]
A few important notes:
Notice the value for :url
key begins with "gitlab://". This is needed for the lein-gitlab-cart
plugin to recognize which url it should register to use its factory class. Behind the scenes the plugin converts the "gitlab://" back into the regular "https://".
If you have multiple packages from different projects under the same gitlab group, you can specify :url
key to be "gitlab://<your_gitlab_domain>/api/v4/groups/<your_group_id>/-/packages/maven". (You can use the tokens of a group to access the packages of the projects it contains)
I found that when using deploy tokens instead of project/group access tokens you need to replace the :username
key to be "Deploy-Token" instead of a "Private-Token".
It is up to you to decide on a way of getting the actual value of the token into the :password
key, but I found it most convenient to just use ~(System/getenv "MY_GITLAB_TOKEN")
to retrieve it from the environment variable.
And, after testing for a few days, I've also reached conclusion that the plugin can only be used to resolve the dependencies mentioned in the :dependencies
vector, it will not work for any private lein plugins you specify in the :plugins
vector. And it seems to be more of an issue with the order in which Leiningen currently (v2.10) resolves the plugin dependencies as the custom wagon factories are only allowed to be registered after all the plugins are resolved (and it cannot happen, because we require lein-gitlab-cart
plugin's wagon factory to resolve the address of our private plugin).
Upvotes: 0