Install gvt
After doing some research, I decided to try gvt
since it seemed simple and well documented, and integrated well with exiting tools like go get
.
1 2 |
|
Go get target project to be updated
I’m going to update todolite-appserver to use vendored dependencies for some of it’s dependencies, just to see how things go.
1
|
|
Vendor dependencies
I’m going to vendor the dependency on kingpin since it has transitive dependencies of it’s own (github.com/alecthomas/units, etc). gvt
handles this by automatically pulling all of the transitive dependencies.
1
|
|
Now my directory structure looks like this:
1 2 3 4 5 6 7 |
|
Here is the manifest
gvt list
shows the following:
1 2 3 4 5 |
|
Verify it’s using the vendor folder
I opened up the vendor/github.com/alecthomas/kingpin/global.go
and made the following change:
1 2 3 4 5 |
|
Now verify that code is getting compiled and run:
1 2 3 |
|
(note: export GO15VENDOREXPERIMENT=1
is still in effect in my shell)
Restore the dependency
Before I check in the vendor
directory to git, I want to reset it to it’s previous state before I made the above change to the global.go
source file.
1
|
|
Now if I open global.go
again, it’s back to it’s original state. Nice!
Add the vendor folder and push
1 2 3 |
|
Also, I updated the README to tell users to set the GO15VENDOREXPERIMENT=1
variable:
1 2 3 |
|
but the instructions otherwise remained the same. If someone tries to use this but forgets to set GO15VENDOREXPERIMENT=1
in Go 1.5, it will still work, it will just use the kingpin dependency in the $GOPATH
rather than the vendor/
directory. Ditto for someone using go 1.4 or earlier.
Removing a vendored dependency
As it turns out, I don’t even need kingpin in this project, since I’m using cobra. The kingpin dependency was caused by some leftover code I forgot to cleanup.
To remove it, I ran:
1 2 3 4 |
|
In this case, since it was my only dependency, it was easy to identify the transitive dependencies. In general though it looks like it’s up to you as a user to track down which ones to remove. I filed gvt issue 16 to hopefully address that.
Editor annoyances
I have emacs setup using the steps in this blog post, and I’m running into the following annoyances:
- When I use
godef
to jump into the code of vendored dependency, it takes me to source code that lives in theGOPATH
, which might be different than what’s undervendor/
. Also, if I edit it there, my changes won’t be reflected when I rebuild. - I usually search for things in the project via
M-x rgrep
, but now it’s searching through every repo undervendor/
and returning things I’m not interested in .. since most of the time I only want to search within my project.