Go dependency management tool experiment (deprecated)
Перейти к файлу
Jelte Fennema e7d8677884 Improve explanation of required based on feedback 2017-07-30 11:49:06 +02:00
.github add jmank88 to MAINTAINERS and CODEOWNERS for gps caching 2017-07-21 06:38:15 -05:00
cmd/dep Default empty constraints to any, not the default branch 2017-07-26 15:45:29 -05:00
docs Improve explanation of required based on feedback 2017-07-30 11:49:06 +02:00
hack Fixed validate-vendor.bash to work with current dep implementation. 2017-05-25 13:18:26 +03:00
internal Merge pull request #901 from carolynvs/default-emptyconstraint-to-unconstrained 2017-07-28 19:11:19 +05:30
testdata Remove trailing spaces from generated Gopkg.toml 2017-06-19 11:54:00 +09:00
vendor/github.com Fix for #820 2017-07-19 06:54:44 -07:00
.codeclimate.yml Exclude testdata dirs from codeclimate 2017-05-26 08:47:29 -04:00
.gitattributes Prevent problems comparing golden files on Windows 2017-02-20 23:45:11 -05:00
.gitignore Ignore output files from a test run 2017-06-08 17:54:30 -05:00
.travis.yml #662 Move HOMEBREW_NO_AUTO_UPDATE to env section 2017-05-28 22:43:22 +02:00
AUTHORS Add repo boilerplate and readme 2016-10-07 11:28:24 +11:00
CODE_OF_CONDUCT.md (To Squash) Moving CODE_OF_CONDUCT.md ../ 2017-04-25 09:11:55 -06:00
CONTRIBUTING.md Move the FAQ under the docs/ folder 2017-07-20 21:09:08 -04:00
CONTRIBUTORS Add repo boilerplate and readme 2016-10-07 11:28:24 +11:00
Gopkg.lock Added Gopkg.lock file .. 2017-07-19 08:02:21 -07:00
Gopkg.toml Support importing glide configuration 2017-06-01 16:22:46 -05:00
LICENSE Add repo boilerplate and readme 2016-10-07 11:28:24 +11:00
MAINTAINERS.md add jmank88 to MAINTAINERS and CODEOWNERS for gps caching 2017-07-21 06:38:15 -05:00
PATENTS Add repo boilerplate and readme 2016-10-07 11:28:24 +11:00
README.md Fix link to docs/Gopkg.toml in README.md 2017-07-26 21:04:40 +02:00
analyzer.go Remove some old TODOs that no longer apply 2017-07-26 16:26:57 -04:00
analyzer_notwindows_test.go Add Windows specific function for making a file unreadable during tests. 2017-05-02 02:34:40 -04:00
analyzer_test.go add new ProjectAnalyzerInfo type to return from ProjectAnalyzer.Info 2017-06-14 18:31:47 -05:00
analyzer_windows_test.go Add Windows specific function for making a file unreadable during tests. 2017-05-02 02:34:40 -04:00
appveyor.yml Only test against Go 1.8 on Windows 2017-06-26 23:59:16 -04:00
context.go remove VersionInWorkspace in favor of Exported absoluteProjectRoot and new gps.ProjectVersion 2017-06-27 07:38:02 -05:00
context_test.go Merge pull request #688 from jmank88/version_in_workspace 2017-07-20 11:02:01 -04:00
doc.go improve godoc; replace Loggers with embeded fields; refactor Ctx api 2017-06-07 08:46:44 -05:00
lock.go rename UnpairedVersion.Is() to Pair() 2017-06-14 09:44:59 -05:00
lock_test.go Modified test files to use project uri's that point to project root rather then submodules. 2017-06-16 08:24:47 -04:00
manifest.go Fixes #429. Removed Manifest.TestDependencyConstraints() and all usage. 2017-06-19 07:02:41 -04:00
manifest_test.go Added check for multiple overrides in manifes files. 2017-06-15 17:35:58 -04:00
project.go updated fs.isDir to always return an error even if the directory is not found 2017-07-10 10:05:03 -04:00
project_test.go improve godoc; replace Loggers with embeded fields; refactor Ctx api 2017-06-07 08:46:44 -05:00
test_project_context_test.go improve godoc; replace Loggers with embeded fields; refactor Ctx api 2017-06-07 08:46:44 -05:00
txn_writer.go Fully embrace subtests; remove hacky targeting arg 2017-07-19 23:28:48 -04:00
txn_writer_test.go unexport and re-locate PruneProject and helpers 2017-07-13 07:50:29 -05:00

README.md

Dep

Linux: Build Status | Windows: Build status | Code Climate

Dep is a prototype dependency management tool. It requires Go 1.7 or newer to compile.

dep is NOT an official tool. Yet. Check out the Roadmap!

Current status

dep is safe for production use. That means two things:

  • Any valid metadata file (Gopkg.toml and Gopkg.lock) will be readable and considered valid by any future version of dep.
  • Generally speaking, it has comparable or fewer bugs than other tools out there.

That said, keep in mind the following:

  • dep is still changing rapidly. If you need stability (e.g. for CI), it's best to rely on a released version, not tip.
  • Some changes are pending to the CLI interface. Scripting on dep before they land is unwise.
  • dep's exported API interface will continue to change in unpredictable, backwards-incompatible ways until we tag a v1.0.0 release.

Context

Setup

Get the tool via

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

To start managing dependencies using dep, run the following from your project root directory:

$ dep init

This does the following:

  1. Look for existing dependency management files to convert
  2. Check if your dependencies use dep
  3. Identify your dependencies
  4. Back up your existing vendor/ directory (if you have one) to _vendor-TIMESTAMP/
  5. Pick the highest compatible version for each dependency
  6. Generate Gopkg.toml ("manifest") and Gopkg.lock files
  7. Install the dependencies in vendor/

Usage

There is one main subcommand you will use: dep ensure. ensure first makes sure Gopkg.lock is consistent with your imports and Gopkg.toml. If any changes are detected, it then populates vendor/ with exactly what's described in Gopkg.lock.

dep ensure is safe to run early and often. See the help text for more detailed usage instructions.

$ dep help ensure

Installing dependencies

(if your vendor/ directory isn't checked in with your code)

$ dep ensure

If a dependency already exists in your vendor/ folder, dep will ensure it matches the constraints from the manifest. If the dependency is missing from vendor/, the latest version allowed by your manifest will be installed.

Adding a dependency

  1. import the package in your *.go source code file(s).

  2. Run the following command to update your Gopkg.lock and populate vendor/ with the new dependency.

    $ dep ensure
    

Changing dependencies

If you want to:

  • Change the allowed version/branch/revision
  • Switch to using a fork

for one or more dependencies, do the following:

  1. Modify your Gopkg.toml.

  2. Run

    $ dep ensure
    

Checking the status of dependencies

Run dep status to see the current status of all your dependencies.

$ dep status
PROJECT                             CONSTRAINT     VERSION        REVISION  LATEST
github.com/Masterminds/semver       branch 2.x     branch 2.x     139cc09   c2e7f6c
github.com/Masterminds/vcs          ^1.11.0        v1.11.1        3084677   3084677
github.com/armon/go-radix           *              branch master  4239b77   4239b77

On top of that, if you have added new imports to your project or modified the manifest file without running dep ensure again, dep status will tell you there is a mismatch between the lock file and the current status of the project.

$ dep status
Lock inputs-digest mismatch due to the following packages missing from the lock:

PROJECT                         MISSING PACKAGES
github.com/Masterminds/goutils  [github.com/Masterminds/goutils]

This happens when a new import is added. Run `dep ensure` to install the missing packages.

As dep status suggests, run dep ensure to update your lockfile. Then run dep status again, and the lock mismatch should go away.

Updating dependencies

(to the latest version allowed by the manifest)

$ dep ensure -update

Removing dependencies

  1. Remove the imports and all usage from your code.

  2. Run

    $ dep ensure
    
  3. Remove from Gopkg.toml, if it was in there.

Testing changes to a dependency

Making changes in your vendor/ directory directly is not recommended, as dep will overwrite any changes. Instead:

  1. Delete the dependency from the vendor/ directory.

    rm -rf vendor/<dependency>
    
  2. Add that dependency to your GOPATH, if it isn't already.

    $ go get <dependency>
    
  3. Modify the dependency in $GOPATH/src/<dependency>.

  4. Test, build, etc.

Don't run dep ensure until you're done. dep ensure will reinstall the dependency into vendor/ based on your manifest, as if you were installing from scratch.

This solution works for short-term use, but for something long-term, take a look at virtualgo.

To test out code that has been pushed as a new version, or to a branch or fork, see changing dependencies.

Semantic Versioning

dep ensure a uses an external semver library to interpret the version constraints you specify in the manifest. The comparison operators are:

  • =: equal
  • !=: not equal
  • >: greater than
  • <: less than
  • >=: greater than or equal to
  • <=: less than or equal to
  • -: literal range. Eg: 1.2 - 1.4.5 is equivalent to >= 1.2, <= 1.4.5
  • ~: minor range. Eg: ~1.2.3 is equivalent to >= 1.2.3, < 1.3.0
  • ^: major range. Eg: ^1.2.3 is equivalent to >= 1.2.3, < 2.0.0
  • [xX*]: wildcard. Eg: 1.2.x is equivalent to >= 1.2.0, < 1.3.0

You might, for example, include a constraint in your manifest that specifies version = "=2.0.0" to pin a dependency to version 2.0.0, or constrain to minor releases with: version = "2.*". Refer to the semver library documentation for more info.

Note: When you specify a version without an operator, dep automatically uses the ^ operator by default. dep ensure will interpret the given version as the min-boundry of a range, for example:

  • 1.2.3 becomes the range >=1.2.3, <2.0.0
  • 0.2.3 becomes the range >=0.2.3, <0.3.0
  • 0.0.3 becomes the range >=0.0.3, <0.1.0

Feedback

Feedback is greatly appreciated. At this stage, the maintainers are most interested in feedback centered on the user experience (UX) of the tool. Do you have workflows that the tool supports well, or doesn't support at all? Do any of the commands have surprising effects, output, or results? Please check the existing issues and FAQ to see if your feedback has already been reported. If not, please file an issue, describing what you did or wanted to do, what you expected to happen, and what actually happened.

Contributing

Contributions are greatly appreciated. The maintainers actively manage the issues list, and try to highlight issues suitable for newcomers. The project follows the typical GitHub pull request model. See CONTRIBUTING.md for more details. Before starting any work, please either comment on an existing issue, or file a new one.