Go dependency management tool-dep

  Dependency management tools, golang

Go dependency management tools

Go dependency management tool

Environmental requirements

  • Golang >= 1.9
  • Dep

Current version:

 version     : devel
 build date  : 
 git hash    : 
 go version  : go1.10
 go compiler : gc
 platform    : linux/amd64

Latest releaseForv0.4.1


go get -u github.com/golang/dep/cmd/dep

If$GOPATH/binabsentPATH, you need to convert the generateddepFile from$GOPATH/binMove to$GOBIANunder


$ dep
Dep is a tool for managing dependencies for Go projects

Usage: "dep [command]"


  init     Set up a new Go project, or migrate an existing one
  status   Report the status of the project's dependencies
  ensure   Ensure a dependency is safely vendored in the project
  prune    Pruning is now performed automatically by dep ensure.
  version  Show the dep version information

  dep init                               set up a new project
  dep ensure                             install the project's dependencies
  dep ensure -update                     update the locked versions of all dependencies
  dep ensure -add github.com/pkg/errors  add a dependency to the project

Use "dep help [command]" for more information about a command.


Execute the initialization command at the root directory of the project.depDuring initialization, all dependent packages required by the application are analyzed to obtain a list of dependent packages

And generatevendorDirectory,Gopkg.tomlGopkg.lockFile


Default initialization

$ dep init -v

Download directly from the corresponding network resources

Priority initialization from $GOPATH

$ dep init -gopath -v

The command starts with$GOPATHFind the existing dependency package and download it from the corresponding network resource if it does not exist.


This document is composed ofdep initGeneration, including managementdepStatement of rules for conduct

required = ["github.com/user/thing/cmd/thing"]

ignored = [

key1 = "value that convey data to other systems"
system1-data = "value that is used by a system"
system2-data = "value that is used by another system"

  # Required: the root import path of the project being constrained.
  name = "github.com/user/project"
  # Recommended: the version constraint to enforce for the project.
  # Note that only one of "branch", "version" or "revision" can be specified.
  version = "1.0.0"
  branch = "master"
  revision = "abc123"

  # Optional: an alternate location (URL or import path) for the project's source.
  source = "https://github.com/myfork/package.git"

  # Optional: metadata about the constraint or override that could be used by other independent systems
  key1 = "value that convey data to other systems"
  system1-data = "value that is used by a system"
  system2-data = "value that is used by another system"


This document is composed ofdep ensureAnddep initGenerated, containing a complete snapshot of the project dependency graph, expressed as a series of[[project]]Section

# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.

  branch = "master"
  name = "github.com/golang/protobuf"
  packages = [
  revision = "bbd03ef6da3a115852eaf24c8a1c46aeb39aa175"

Common commands

dep ensure

From theGopkg.tomlAndGopkg.lockAnalyze the diagram in and obtain the required dependency packages

It is used to ensure that the local diagrams, locks and dependency package lists are completely consistent.

dep ensure -add

# 引入该依赖包的最新版本
dep ensure -add github.com/pkg/foo

# 引入具有特定约束(指定版本)的依赖包
dep ensure -add github.com/pkg/foo@^1.0.1

dep ensure -update

willGopkg.lockThe contract dependency in is updated toGopkg.tomlThe latest version allowed


At presentdepIt is still in the official test stage, but has said that the production can be used safely.

If there is any problem, everyone can leave a message to discuss it.