I am moving a few private Go projects to GitLab while getting rid of Godeps
, Go dep
with vendor
directory and all of that because I would like to use just Go modules.
I am using Go version: go1.12.6 linux/amd64
.
- I have a private "library" project / git repository at
gitlab.com/my-company/my-team/my-library
. This works as a Go module withgo.mod
andgo.sum
. - I would like to use
my-library
as a dependency for another project, this:gitlab.com/my-company/my-team/my-project
.
The structure of the URL is the same, the only thing that changes is the name of the repository.
I am facing all sorts of errors while importing my-library
in my-project
.
- How can I import Go modules as private repositories inside other Go modules as private repositories?
- What's wrong with the command outputs below?
I know the GitLab tokens work because the go get
command figures out itself the commit ID of my-library
. Anyway I've done the following (see https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html):
git config \
--global \
url."https://token_name:token_val@gitlab.com".insteadOf \
"https://gitlab.com"
These are the error messages:
$ go get -u gitlab.com/my-company/my-team/my-library.git
go: finding gitlab.com/my-company/my-team/my-library.git latest
go: gitlab.com/my-company/my-team/my-library.git@v0.0.0-20190802120216-712a10fb5fac: parsing go.mod: unexpected module path "gitlab.com/my-company/my-team/my-library"
go get: error loading module requirements
$
$ go get -u gitlab.com/my-company/my-team/my-library
go get gitlab.com/my-company/my-team/my-library: git ls-remote -q https://gitlab.com/my-company/my-team.git in /home/foo/Development/go-workspace/pkg/mod/cache/vcs/9be637426eac43b329899d57d9375d12246f2cc0f6ddd098446bc42ed1ca534d: exit status 128:
remote: The project you were looking for could not be found.
fatal: repository 'https://token_name:token_val@gitlab.com/my-company/my-team.git/' not found
$
$ GO111MODULE=off go get -u gitlab.com/my-company/my-team/my-library.git
package gitlab.com/my-company/my-team/my-library.git: no Go files in /home/foo/Development/go-workspace/src/gitlab.com/my-company/my-team/my-library.git
$
- The first attempt is the one I think I should use, but it does not work and I don't know why.
- I thought this was happening because somehow there was already a dependency like this in the project. But when executing
go mod graph | grep gitlab
I find an empty output, i.e. there is no conflicting dependency.
- I thought this was happening because somehow there was already a dependency like this in the project. But when executing
- The second attempt is probably to be avoided because the URL does not end with
.git
and (for some reason that I don't understand) the URL is cut at the level ofmy-team
. GO111MODULE=off
seems to forcego get
to check in$GOPATH
which I think I should avoid at all, but I was just trying to see if that way I was able to fetch that dependency.