blob: 480f92e0b0d84f46b78efdf020563c38e2f30350 [file] [log] [blame] [view]
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -04001# Go 1.11 Modules
Bryan C. Mills75f81732018-07-16 14:15:15 -04002
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -04003Go 1.11 will add preliminary support for versioned modules as proposed [here](https://golang.org/design/24301-versioned-go).
Bryan C. Mills75f81732018-07-16 14:15:15 -04004
thepudds847a5de2018-07-27 07:54:08 -04005Go modules will be an [experimental](https://research.swtch.com/vgo-accepted) opt-in feature in Go 1.11, with the hope of incorporating feedback and finalizing the feature for Go 1.12. Even though the details may change, future releases will support modules defined using Go 1.11 or `vgo`.
thepuddsf398d512018-07-22 18:10:33 -04006
7## Current Status
8
thepuddsc7f8aed2018-08-01 01:34:33 -04009* The recent work by the Go team on versioned Go modules started outside of the main Go repository with the `vgo` tool, but on **July 12, 2018** support for versioned Go modules **landed in the main Go repository** ([announcement thread](https://groups.google.com/d/msg/golang-dev/a5PqQuBljF4/61QK4JdtBgAJ)).
thepudds5af74db2018-08-01 18:14:36 -040010 * Development work on modules is now occurring exclusively in the main Go repository, with a periodic export to the vgo repository for people still using `vgo`.
thepuddsa7ce6d72018-08-05 09:34:37 -040011* Beta support for modules is now also available:
thepudds170f51d2018-08-09 06:41:45 -040012 * Initial beta started with [Go 1.11 beta 2](https://groups.google.com/d/msg/golang-dev/A6TCp2kCoss/XLQoI4MeBgAJ) (released on **July 20, 2018**).
Fazlul Shahriar5c828402018-08-05 12:07:17 -040013 * **Latest beta** is [Go 1.11 beta 3](https://groups.google.com/d/msg/golang-nuts/vOMqDrIwxBo/-wJvN12oCwAJ) (released on **August 3, 2018**).
thepudds6f434ef2018-08-13 13:29:51 -040014* Beta 3 and `master` include some significant changes for the `go mod` commands. See FAQ [below](https://github.com/golang/go/wiki/Modules#how-have-the-go-mod-commands-changed-recently-in-go111beta3) for an overview of these changes.
thepuddsf398d512018-07-22 18:10:33 -040015
thepuddsa7ce6d72018-08-05 09:34:37 -040016**NOTE:** Some issues you might experience:
thepudds6f434ef2018-08-13 13:29:51 -040017* There are some regressions in beta 3 compared to beta 2 (e.g., [#26722](https://github.com/golang/go/issues/26722) and [#26602](https://github.com/golang/go/issues/26602), both fixed in `master`)
thepuddsa7ce6d72018-08-05 09:34:37 -040018* Some older versions of git might not work:
19 * [#26501](https://github.com/golang/go/issues/26501) covers git 2.10.0 and earlier not working. (Fixed in beta 3 but not fixed in beta 2).
thepudds7b9e5bb2018-08-05 09:55:03 -040020 * [#26594](https://github.com/golang/go/issues/26594) appears to be different problem than #26501 but might be related to older git as well. (Not fixed in beta 3 -- help triaging this particular issue is welcomed).
21 * [#26754](https://github.com/golang/go/issues/26754) is example where git 2.18.0 succeeds, but git 2.7.4 can't resolve a commit unreachable from any branch.
thepudds634f3412018-07-28 15:27:09 -040022
thepuddsfc0364b2018-08-02 22:10:15 -040023## Table of Contents
24
thepuddse4474f22018-08-02 22:26:17 -040025The remaining content on this page is organized as follows:
thepuddsfc0364b2018-08-02 22:10:15 -040026* [Installing and Activating Module Support](https://github.com/golang/go/wiki/Modules#installing-and-activating-module-support)
27* [New Concepts](https://github.com/golang/go/wiki/Modules#new-concepts)
thepuddsfc0364b2018-08-02 22:10:15 -040028 * [Modules](https://github.com/golang/go/wiki/Modules#modules)
thepudds0e8012e2018-08-05 12:24:11 -040029 * [go.mod](https://github.com/golang/go/wiki/Modules#gomod)
thepuddsfc0364b2018-08-02 22:10:15 -040030 * [Version Selection](https://github.com/golang/go/wiki/Modules#version-selection)
thepudds14331902018-08-05 12:09:17 -040031 * [Semantic Import Versioning](https://github.com/golang/go/wiki/Modules#semantic-import-versioning)
thepuddsfc0364b2018-08-02 22:10:15 -040032* [How to Define a Module](https://github.com/golang/go/wiki/Modules#how-to-define-a-module)
33* [How to Upgrade and Downgrade Dependencies](https://github.com/golang/go/wiki/Modules#how-to-upgrade-and-downgrade-dependencies)
34* [How to Prepare for a Release](https://github.com/golang/go/wiki/Modules#how-to-prepare-for-a-release)
35* [Additional Resources](https://github.com/golang/go/wiki/Modules#additional-resources)
36* [Changes Since the Initial Vgo Proposal](https://github.com/golang/go/wiki/Modules#changes-since-the-initial-vgo-proposal)
37* [GitHub Issues](https://github.com/golang/go/wiki/Modules#github-issues)
38* [FAQ](https://github.com/golang/go/wiki/Modules#faq)
39
thepudds847a5de2018-07-27 07:54:08 -040040## Installing and Activating Module Support
Bryan C. Mills75f81732018-07-16 14:15:15 -040041
thepudds847a5de2018-07-27 07:54:08 -040042To use modules, you currently have three install options:
thepuddsfd489a12018-08-01 02:47:49 -040043* [Install the Go toolchain from source](https://golang.org/doc/install/source) on the `master` branch.
Dmitry Savintsevcff8bfd2018-08-08 12:33:40 +020044* [Install Go 1.11 beta 3](https://groups.google.com/forum/#!topic/golang-dev/7u0nPlsup5I) (and replace `go` with `go1.11beta3` in the commands below).
thepuddsfd489a12018-08-01 02:47:49 -040045* Install the `vgo` binary from the [`vgo` subrepository](https://github.com/golang/vgo) (and replace `go` with `vgo` in the commands below).
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -040046
thepuddseef37be2018-07-27 08:35:11 -040047Once installed, you can then activate module support in one of three ways:
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -040048* Invoke the `go` command in a directory outside of the `$GOPATH/src` tree, with a valid `go.mod` file in the current directory or any parent of it and the environment variable `GO111MODULE` unset (or explicitly set to `auto`).
49* Invoke the `go` command with `GO111MODULE=on` in the command environment.
thepuddsfd489a12018-08-01 02:47:49 -040050* Invoke the binary named `vgo` (if you have installed `vgo` from the subrepository).
Bryan C. Mills75f81732018-07-16 14:15:15 -040051
thepudds140883f2018-08-13 13:10:20 -040052In addition to trying modules-specific workflows:
53* There is also benefit in running your general tests to catch any new issues early.
54* Please consider adding `1.11beta3` or similar to your CI (such as in this example [Travis yaml file](https://github.com/gomods/athens/blob/master/.travis.yml#L6), or following the build matrix pattern shown in this [CircleCI 2.0 yaml file](https://discuss.circleci.com/t/build-matrix-configuration/14448); see [this thread](https://groups.google.com/d/msg/golang-dev/ONpj39nviNg/Zn9rPADhCwAJ) for more related discussion).
55
Bryan C. Mills75f81732018-07-16 14:15:15 -040056## New Concepts
57
thepudds0e8012e2018-08-05 12:24:11 -040058These sections provide a high-level introduction to the main new concepts. For more details and rationale, please see [the official proposal document](), this 40 minute introductory [video by Russ Cox describing the philosophy behind the design](https://www.youtube.com/watch?v=F8nrpe0XWRg&list=PLq2Nv-Sh8EbbIjQgDzapOFeVfv5bGOoPE&index=3&t=0s), or the more detailed initial [vgo blog series](https://research.swtch.com/vgo).
59
Bryan C. Mills75f81732018-07-16 14:15:15 -040060### Modules
61
thepudds0e8012e2018-08-05 12:24:11 -040062A module is a collection of related Go packages that are versioned together as a single unit. Most often, a single version-control repository corresponds exactly to a single module, but alternatively a single version-control repository can hold multiple modules.
Bryan C. Mills75f81732018-07-16 14:15:15 -040063
thepudds80d05d32018-08-13 07:38:09 -040064Modules must be [semantically versioned](https://semver.org/) in the form `v(major).(minor).(patch)`, such as `v0.1.0`, `v1.2.3`, or `v3.0.1`. If using Git, [tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging) released commits with their versions. (Stand-alone distributed module repositories, such as [Project Athens](https://github.com/gomods/athens), are in the works.)
65
thepudds0e8012e2018-08-05 12:24:11 -040066### go.mod
67
68A module is defined by a tree of Go source files with a `go.mod` file in the tree's root directory. Module source code may be located outside of $GOPATH.
69
thepudds4975e282018-08-05 12:47:20 -040070All of the packages in a module share a common prefix -- the module path. The `go.mod` file defines the module path via the `module` directive. For example, the first line in a `go.mod` file typically would be `module example.com/my/module` if it was defining a module for packages `example.com/my/module/pkg/foo` and `example.com/my/module/pkg/bar`.
thepudds0e8012e2018-08-05 12:24:11 -040071
72Module files may include comments and will look familiar to a go programmer. Here is an example go.mod file:
73
Bryan C. Mills75f81732018-07-16 14:15:15 -040074```
75module github.com/kardianos/vmain/v3
76
77require (
thepudds0e8012e2018-08-05 12:24:11 -040078 github.com/kardianos/vtest v1.0.2
Bryan C. Mills75f81732018-07-16 14:15:15 -040079)
80```
81
thepudds0e8012e2018-08-05 12:24:11 -040082There are 4 directives: `module`, `require`, `exclude`, `replace`. Module paths may be quoted but are not required to be.
Bryan C. Mills75f81732018-07-16 14:15:15 -040083
thepudds0e8012e2018-08-05 12:24:11 -040084`exclude` and `replace` directives only operate on the current (“main”) module. `exclude` and `replace` directives in modules other than the main module are ignored when building the main module. The `replace` and `exclude` statements therefore allow the main module complete control over its own build, without also being subject to complete control by dependencies. (TODO: show example exclude and replace directives and/or FAQ on when to use them).
Bryan C. Mills75f81732018-07-16 14:15:15 -040085
thepudds0e8012e2018-08-05 12:24:11 -040086In Go source code, packages are imported using the full path including the module, for example:
87 * `import "example.com/my/module/v2/pkg/foo"` to import `foo` from module `example.com/my/module/v2`.
Bryan C. Mills75f81732018-07-16 14:15:15 -040088
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -040089### Version Selection
Bryan C. Mills75f81732018-07-16 14:15:15 -040090
thepudds0e8012e2018-08-05 12:24:11 -040091If you add a new import to your source code that is not yet covered by a `require` in `go.mod`, any go command run (e.g., 'go build') will automatically look up the proper module and add the *highest* version of that new direct dependency to your module's `go.mod` as a `require` directive. For example, if your new import corresponds to dependency M whose latest tagged release version is `v1.2.3`, your module's `go.mod` will end up with `require M v1.2.3`, which indicates module M is a dependency with allowed version >= v1.2.3 (and < v2, given v2 is considered incompatible with v1).
thepudds5af74db2018-08-01 18:14:36 -040092
thepuddsca4878d2018-08-03 13:06:14 -040093The *minimal version selection* algorithm is used to select the versions of all modules used in a build. For each module in a build, the version selected by minimal version selection is always the semantically *highest* of the versions explicitly listed by a `require` directive in the main module or one of its dependencies. This effectively locks each version into place until the module author or user chooses an explicit new version or chooses to upgrade to the latest available version.
Bryan C. Mills75f81732018-07-16 14:15:15 -040094
thepuddsc164d5a2018-08-03 13:04:28 -040095For example, if your module A depends on B which has a `require D v1.0.0`, and your module also depends on module C which has a `require D v1.1.0`, then minimal version selection would choose `v1.1.0` of D to include in the build (even if a version v1.2.0 of D is available).
96
thepudds91ffcea2018-08-02 23:55:11 -040097For a brief rationale and overview of the minimal version selection algorithm, [see the "High Fidelity Builds" section](https://github.com/golang/proposal/blob/master/design/24301-versioned-go.md#update-timing--high-fidelity-builds) of the official proposal, or see the [more detailed `vgo` blog series](https://research.swtch.com/vgo).
thepudds5077edf2018-08-02 09:01:12 -040098
thepudds01d386c2018-08-02 09:48:29 -040099To see a list of the selected module versions, use `go list -m`.
Bryan C. Mills75f81732018-07-16 14:15:15 -0400100
thepudds0168d012018-08-02 22:24:15 -0400101See also the ["How to Upgrade and Downgrade Dependencies"](https://github.com/golang/go/wiki/Modules#how-to-upgrade-and-downgrade-dependencies) section below and the ["How are versions marked as incompatible?"](https://github.com/golang/go/wiki/Modules#how-are-versions-marked-as-incompatible) FAQ below.
thepudds5af74db2018-08-01 18:14:36 -0400102
thepudds14331902018-08-05 12:09:17 -0400103### Semantic Import Versioning
104
thepudds74c22d72018-08-05 12:50:37 -0400105The major version of a module must be included in both the module path and the package import path if the major version is v2 or higher, such as `me.io/my/mod/v2/pkg`. Module versions of v1 and v0 must not be included in the path. In Go, packages with different import paths (e.g., due to different major versions) are different packages. Thus `me.io/my/mod/pkg` is a different package than `me.io/my/mod/v2/pkg`, and both may be imported in a single build, which among other benefits allows a v1 module to be implemented in terms of its v2 replacement or vice versa.
thepudds14331902018-08-05 12:09:17 -0400106
thepudds0e8012e2018-08-05 12:24:11 -0400107Including major versions in import paths will produce incompatibilities with old versions of Go. To work around this prior versions of the go tool have been updated and released to continue building as before when they encounter major versions in import paths. (See [issue 25069](https://github.com/golang/go/issues/25069).)
108
109There are two ways to release a v2 or higher module version. Using the example of creating a `v2.0.0` release, the two options are:
1101. Update the `go.mod` file to include a `/v2` at the end of the module path. Tag the release with `v2.0.0`.
111 * To avoid confusion with this approach, consider putting the `v2.*.*` commits on a separate v2 branch.
1122. Alternatively, create a `v2` directory and place a new `go.mod` file in that directory. The module path must end with `/v2`. Tag the release with `v2.0.0`.
113
thepudds14331902018-08-05 12:09:17 -0400114The behavior of modules for existing packages with post-`v1` tags is still in flux; an important related recent change was [issue 26238](https://golang.org/issue/26238), which substantially [improved the behavior](https://github.com/golang/go/issues/25967#issuecomment-407567904) for existing packages with post-`v1` tags.
115
thepudds88919642018-08-02 21:51:04 -0400116## How to Define a Module
Bryan C. Mills75f81732018-07-16 14:15:15 -0400117
thepuddsfd489a12018-08-01 02:47:49 -0400118To create a `go.mod` for an existing project:
Bryan C. Mills75f81732018-07-16 14:15:15 -0400119
thepudds6f427542018-07-31 13:33:16 -04001201. Navigate to the root of the module's source tree and activate module mode in the `go` command:
Bryan C. Mills75f81732018-07-16 14:15:15 -0400121
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -0400122 ```
123 $ cd $GOPATH/src/<project path>
124 $ export GO111MODULE=on
125 ```
Bryan C. Mills75f81732018-07-16 14:15:15 -0400126
thepudds6f427542018-07-31 13:33:16 -0400127 or:
Bryan C. Mills75f81732018-07-16 14:15:15 -0400128
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -0400129 ```
130 $ cd <project path outside $GOPATH/src>
131 ```
Bryan C. Mills75f81732018-07-16 14:15:15 -0400132
thepudds6f427542018-07-31 13:33:16 -04001332. Create the initial module definition and write it to the `go.mod` file:
Bryan C. Mills75f81732018-07-16 14:15:15 -0400134
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -0400135 ```
thepudds6f434ef2018-08-13 13:29:51 -0400136 # if using 'master', go1.11beta3, or the latest `vgo`, use the newer form:
137 $ go mod init
thepuddsf1054312018-08-01 01:30:34 -0400138
thepudds6f434ef2018-08-13 13:29:51 -0400139 # in go1.11beta2 and earlier, the older form was:
140 $ go mod -init
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -0400141 ```
Bryan C. Mills75f81732018-07-16 14:15:15 -0400142
thepudds9bdb2722018-07-27 07:02:48 -0400143 This step converts from any existing [`dep`](https://github.com/golang/dep) `Gopkg.lock` file or from any of the other [nine total supported dependency formats](https://tip.golang.org/pkg/cmd/go/internal/modconv/?m=all#pkg-variables), adding require statements to match the existing configuration.
Bryan C. Mills75f81732018-07-16 14:15:15 -0400144
thepudds6f434ef2018-08-13 13:29:51 -0400145 If `go mod` cannot automatically determine an appropriate module path (e.g., if running outside of VCS), or if you need to override that path, use the `-module` flag:
Bryan C. Mills75f81732018-07-16 14:15:15 -0400146
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -0400147 ```
thepudds6f434ef2018-08-13 13:29:51 -0400148 # if using 'master', go1.11beta3, or the latest `vgo`, use the newer form:
thepuddsf1054312018-08-01 01:30:34 -0400149 $ go mod init example.com/my/module/v2
thepudds6f434ef2018-08-13 13:29:51 -0400150
151 # in go1.11beta2 and earlier, the older form was:
152 $ go mod -init -module example.com/my/module/v2
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -0400153 ```
Bryan C. Mills75f81732018-07-16 14:15:15 -0400154
thepudds74241a12018-07-31 13:31:00 -04001553. Build the module. This will automatically add missing or unconverted dependencies as needed to satisfy imports for this particular build invocation:
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -0400156
157 ```
thepudds74241a12018-07-31 13:31:00 -0400158 $ go build ./...
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -0400159 ```
thepudds6f427542018-07-31 13:33:16 -04001604. Test the module as configured to ensure that it works with the selected versions:
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -0400161
162 ```
163 $ go test ./...
164 ```
165
thepudds5af74db2018-08-01 18:14:36 -04001665. (Optional) Run the tests for all imported modules (direct and indirect dependencies) to check for incompatibilities:
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -0400167
168 ```
thepudds4b3d8932018-07-27 06:50:53 -0400169 $ go test all
Bryan C. Mills0d7c8e02018-07-16 15:50:05 -0400170 ```
Bryan C. Mills75f81732018-07-16 14:15:15 -0400171
thepudds0168d012018-08-02 22:24:15 -0400172Prior to tagging a release, see the ["How to Prepare for a Release"](https://github.com/golang/go/wiki/Modules#how-to-prepare-for-a-release) section below.
thepudds74241a12018-07-31 13:31:00 -0400173
thepudds432bda32018-08-07 05:22:33 -0400174For more information on all of these topics, the primary entry point to the official modules documentation is [available on tip.golang.org](https://tip.golang.org/cmd/go/#hdr-Modules__module_versions__and_more).
175
thepudds88919642018-08-02 21:51:04 -0400176## How to Upgrade and Downgrade Dependencies
Bryan C. Mills75f81732018-07-16 14:15:15 -0400177
thepudds4b3d8932018-07-27 06:50:53 -0400178Day-to-day adding, removing, upgrading, and downgrading of dependencies should be done using 'go get', which will automatically update the `go.mod` file.
179
thepudds61c12ce2018-07-27 08:04:34 -0400180In addition, go commands like 'go build', 'go test', or even 'go list' will automatically add new dependencies as needed to satisfy imports (updating `go.mod` and downloading the new dependencies).
thepuddsb05a8442018-07-26 08:18:42 -0400181
thepudds927647d2018-07-26 09:03:39 -0400182To upgrade to the latest version for all transitive dependencies of the current module:
thepudds5af74db2018-08-01 18:14:36 -0400183 * run `go get -u` to use the latest *minor or patch* releases
184 * run `go get -u=patch` to use the latest *patch* releases
thepuddsee879c52018-07-25 12:08:34 -0400185
thepudds8f75c6c2018-08-01 09:18:37 -0400186To upgrade or downgrade to a more specific version, 'go get' allows version selection to be overridden by adding an @version suffix or "module query" to the package argument, such as `go get github.com/gorilla/mux@v1.6.2`, `go get github.com/gorilla/mux@e3702bed2`, or `go get github.com/gorilla/mux@'<v1.6.2'`.
187
188See the ["Module-aware go get"](https://tip.golang.org/cmd/go/#hdr-Module_aware_go_get) and ["Module queries"](https://tip.golang.org/cmd/go/#hdr-Module_queries) sections of the tip documentation for more information on the topics here.
thepuddsb05a8442018-07-26 08:18:42 -0400189
thepudds5af74db2018-08-01 18:14:36 -0400190After upgrading or downgrading any dependencies, you may then want to run the tests again for all imported modules (direct and indirect dependencies) to check for incompatibilities:
thepuddsee879c52018-07-25 12:08:34 -0400191 ```
thepudds4b3d8932018-07-27 06:50:53 -0400192 $ go test all
thepuddsee879c52018-07-25 12:08:34 -0400193 ```
thepuddsf398d512018-07-22 18:10:33 -0400194
thepudds88919642018-08-02 21:51:04 -0400195## How to Prepare for a Release
thepudds61aba5c2018-07-27 07:10:40 -0400196
thepuddsdf13b282018-08-01 00:38:40 -0400197Best practices for creating a release of a module are expected to emerge as part of the initial modules experiment. Many of these might end up being automated by a [future 'go release' tool](https://github.com/golang/go/issues/26420).
thepudds61aba5c2018-07-27 07:10:40 -0400198
thepudds88919642018-08-02 21:51:04 -0400199Some current suggested best practices to consider prior to tagging a release:
thepudds61aba5c2018-07-27 07:10:40 -0400200
thepudds6f434ef2018-08-13 13:29:51 -0400201* Run `go mod tidy` (or if running go1.11beta2 or earlier: `go mod -sync`) to ensure your current go.mod reflects all possible build tags/OS/architecture combinations (as described [here](https://github.com/golang/go/issues/26571)) and possibly prune any extraneous requirements (as described [here](https://tip.golang.org/cmd/go/#hdr-Maintaining_module_requirements)).
thepuddsf918d5c2018-07-31 13:36:22 -0400202
thepudds61aba5c2018-07-27 07:10:40 -0400203* Run `go test all` to test your module (including your direct and indirect dependencies) as a way of validating that the currently selected packages versions are compatible.
thepuddsfd489a12018-08-01 02:47:49 -0400204 * The number of possible version combinations in general is exponential in the number of modules, so you cannot expect your dependencies to have tested against all possible combinations of their dependencies.
thepudds61aba5c2018-07-27 07:10:40 -0400205 * As part of the modules work, `go test all` has been [re-defined to be more useful](https://research.swtch.com/vgo-cmd) to include all the packages in the current module, plus all the packages they depend on through a sequence of one or more imports, while excluding packages that don't matter in the current module.
thepudds61aba5c2018-07-27 07:10:40 -0400206
thepudds8390d032018-07-22 23:37:00 -0400207## Additional Resources
thepuddsf398d512018-07-22 18:10:33 -0400208
thepudds8390d032018-07-22 23:37:00 -0400209### Documentation and Proposal
210
thepuddsfd489a12018-08-01 02:47:49 -0400211* Official documentation:
212 * Latest [HTML documentation for modules on tip.golang.org](https://tip.golang.org/cmd/go/#hdr-Modules__module_versions__and_more)
213 * Run `go help modules` for more about modules. (This is the main entry point for modules topics via `go help`)
214 * Run `go help mod` for more about the `go mod` command.
215 * Run `go help module-get` for more about the behavior of `go get` when in module-aware mode.
216 * Run `go help goproxy` for more about the module proxy, including a pure file-based option via a `file:///` URL.
thepudds592f7432018-07-26 10:03:47 -0400217* The initial ["Go & Versioning"](https://research.swtch.com/vgo) series of blog posts on `vgo` by Russ Cox (first posted February 20, 2018)
218* Official [golang.org blog post introducing the proposal](https://blog.golang.org/versioning-proposal) (March 26, 2018)
219 * This provides a more succinct overview of the proposal than the full `vgo` blog series, along with some of the history and process behind the proposal
thepudds8390d032018-07-22 23:37:00 -0400220* Official [Versioned Go Modules Proposal](https://golang.org/design/24301-versioned-go) (last updated March 20, 2018)
221
222### Introductory Material
223
224* Introductory blog post ["Taking Go Modules for a Spin"](https://dave.cheney.net/2018/07/14/taking-go-modules-for-a-spin) by Dave Cheney (July 14, 2018)
225* Introductory blog post on [how to build go from tip and start using go modules](https://carolynvanslyck.com/blog/2018/07/building-go-from-source/) by Carolyn Van Slyck (July 16, 2018)
226* Introductory [Go Meetup slides on modules](https://docs.google.com/presentation/d/1ansfXN8a_aVL-QuvQNY7xywnS78HE8aG7fPiITNQWMM/edit#slide=id.g3d87f3177d_0_0) by Chris Hines (July 16, 2018)
227* Introductory video ["The Principles of Versions in Go"](https://www.youtube.com/watch?v=F8nrpe0XWRg&list=PLq2Nv-Sh8EbbIjQgDzapOFeVfv5bGOoPE&index=3&t=0s) from GopherCon Singapore by Russ Cox (May 2, 2018)
228 * Succinctly covers the philosophy behind the design of versioned Go modules, including the three core principles of "Compatibility", "Repeatability", and "Cooperation"
229
230### Additional Material
231
thepudds592f7432018-07-26 10:03:47 -0400232* Blog post ["Using Go modules with Travis CI"](https://dave.cheney.net/2018/07/16/using-go-modules-with-travis-ci) by Dave Cheney (July 16, 2018)
233* Blog post ["The vgo proposal is accepted. Now what?"](https://research.swtch.com/vgo-accepted) by Russ Cox (May 29, 2018)
thepudds8390d032018-07-22 23:37:00 -0400234 * Includes summary of what it means that versioned modules are currently an experimental opt-in feature
235
thepudds88919642018-08-02 21:51:04 -0400236## Changes Since the Initial Vgo Proposal
237
thepuddsa7d30542018-08-03 18:02:38 -0400238As part of the proposal, prototype, and beta processes, there have been over 400 issues created by the overall community. Please continue to supply feedback.
239
240Here is a partial list of some of the larger changes and improvements, almost all of which were primarily based on feedback from the community:
thepudds88919642018-08-02 21:51:04 -0400241
242* Top-level vendor support was retained rather than vgo-based builds ignoring vendor directories entirely ([discussion](https://groups.google.com/d/msg/golang-dev/FTMScX1fsYk/uEUSjBAHAwAJ), [CL](https://go-review.googlesource.com/c/vgo/+/118316))
thepudds0168d012018-08-02 22:24:15 -0400243* Backported minimal module-awareness to allow older Go versions 1.9.7+ and 1.10.3+ to more easily consume modules for v2+ projects ([discussion](https://github.com/golang/go/issues/24301#issuecomment-371228742), [CL](https://golang.org/cl/109340))
thepudds42f1dea2018-08-03 18:07:15 -0400244* Allowed vgo to use v2+ tags by default for pre-existing packages did not yet have a go.mod (recent update in related behavior described [here](https://github.com/golang/go/issues/25967#issuecomment-407567904))
thepudds0168d012018-08-02 22:24:15 -0400245* Added support via command `go get -u=patch` to update all transitive dependencies to the latest available patch-level versions on the same minor version ([discussion](https://research.swtch.com/vgo-cmd), [documentation](https://tip.golang.org/cmd/go/#hdr-Module_aware_go_get))
thepudds88919642018-08-02 21:51:04 -0400246* Additional control via environmental variables (e.g., GOFLAGS in [#26585](https://github.com/golang/go/issues/26585), [CL](https://go-review.googlesource.com/c/go/+/126656))
thepudds55989cc2018-08-05 20:39:02 -0400247* Finer grain control on whether or not go.mod is allowed to be updated, how vendor directory is used, and whether or not network access is allowed (e.g., -mod=readonly, -mod=vendor, GOPROXY=off; related [CL](https://go-review.googlesource.com/c/go/+/126696) for recent change)
thepudds0168d012018-08-02 22:24:15 -0400248* Added more flexible replace directives ([CL](https://go-review.googlesource.com/c/vgo/+/122400))
249* Added additional ways to interrogate modules (for human consumption, as well as for better editor / IDE integration)
250* The UX of the go CLI has continued to be refined based on experiences so far (e.g., [#26581](https://github.com/golang/go/issues/26581), [CL](https://go-review.googlesource.com/c/go/+/126655))
thepudds88919642018-08-02 21:51:04 -0400251* **Most likely:** additional support for warming caches for use cases such as CI or docker builds ([#26610](https://github.com/golang/go/issues/26610#issuecomment-408654653))
252* **Most likely**: better support for installing specific versions of programs to GOBIN ([#24250](https://github.com/golang/go/issues/24250#issuecomment-377553022))
253
thepudds88919642018-08-02 21:51:04 -0400254## GitHub Issues
thepudds8390d032018-07-22 23:37:00 -0400255
thepuddsdf13b282018-08-01 00:38:40 -0400256* [Currently open module issues](https://golang.org/issues?q=is%3Aopen+is%3Aissue+label:modules)
257* [Closed module issues](https://golang.org/issues?q=is%3Aclosed+is%3Aissue+label:modules)
258* [Closed vgo issues](https://github.com/golang/go/issues?page=3&q=-label%3Amodules+vgo+is%3Aclosed)
thepuddse01f40e2018-08-01 01:05:48 -0400259* Submit a [new module issue](https://github.com/golang/go/issues/new?title=cmd%2Fgo%3A%20%3Cfill%20this%20in%3E) using 'cmd/go:' as the prefix
260
261## FAQ
262
263### How are versions marked as incompatible?
264
thepuddsd9442592018-08-02 09:44:49 -0400265The `require` directive allows any module to declare that it should be built with version >= x.y.z of a dependency D (which may be specified due to incompatibilities with version < x.y.z of module D). Empirical data suggests [this is the dominant form of constraints used in `dep` and `cargo`](https://twitter.com/_rsc/status/1022590868967116800). In addition, the top-level module in the build can `exclude` specific versions of dependencies or `replace` other modules with different code. See the full proposal for [more details and rationale](https://github.com/golang/proposal/blob/master/design/24301-versioned-go.md).
thepuddse01f40e2018-08-01 01:05:48 -0400266
thepudds601d2312018-08-06 23:26:24 -0400267One of the key goals of the versioned modules proposal is to add a common vocabulary and semantics around versions of Go code for both tools and developers. This lays a foundation for future capabilities to declare additional forms of incompatibilities, such as possibly:
thepudds0bb0f8d2018-08-01 01:51:19 -0400268* declaring deprecated versions as [described](https://research.swtch.com/vgo-module) in the initial `vgo` blog series
thepuddse01f40e2018-08-01 01:05:48 -0400269* declaring pair-wise incompatibility between modules in an external system as discussed for example [here](https://github.com/golang/go/issues/24301#issuecomment-392111327) during the proposal process
thepuddsd9442592018-08-02 09:44:49 -0400270* declaring incompatible versions or insecure versions of a module after a release has been published. See for example the on-going discussion in [#24031](https://github.com/golang/go/issues/24031#issuecomment-407798552)
thepuddse01f40e2018-08-01 01:05:48 -0400271
Dmitry Savintsev0e8db232018-08-08 12:28:04 +0200272### How have the `go mod` commands changed recently in `go1.11beta3`?
thepuddse01f40e2018-08-01 01:05:48 -0400273
Dmitry Savintsev0e8db232018-08-08 12:28:04 +0200274As of go1.11beta3, there has been a significant change for the `go mod` commands. See https://tip.golang.org/cmd/go/#hdr-Module_maintenance as well as two snippets from the [CL](https://go-review.googlesource.com/c/go/+/126655) briefly covering the rationale and the list of new vs. old commands:
thepuddse01f40e2018-08-01 01:05:48 -0400275```
276The current "go mod" command does too many things.
277
278It looks like "everything you might want to do with modules"
279which causes people to think all module operations go through
280"go mod", which is the opposite of the seamless integration we're
281going for. In particular too many people think "go mod -require"
282and "go get" are the same.
283```
284and:
285```
286split "go mod" into multiple subcommands:
287
288 go mod edit # old go mod -require ...
289 go mod fix # old go mod -fix
290 go mod graph # old go mod -graph
291 go mod init # old go mod -init
292 go mod tidy # old go mod -sync
293 go mod vendor # old go mod -vendor
294 go mod verify # old go mod -verify
295
296Splitting out the individual commands makes both the docs
297and the implementations dramatically easier to read.
298It simplifies the command lines
299(go mod -init -module m is now 'go mod init m')
300and allows command-specific flags.
301```
302
thepudds1da29f62018-08-05 11:19:52 -0400303### My project has historically made breaking changes without bumping the major version. What are some strategies to consider moving forward?
304
thepudds162ccfe2018-08-05 11:27:29 -0400305In response to a question *"k8s does minor releases but changes the Go API in each minor release. How would people handle importing k8s as a vendored project via vgo?"*, Russ Cox made the following [comment](https://github.com/kubernetes/kubernetes/pull/65683#issuecomment-403705882):
thepudds1da29f62018-08-05 11:19:52 -0400306
307> I don't fully understand the k8s dev cycle etc, but I think generally the k8s team needs to decide/confirm what they intend to guarantee to users about stability and then apply version numbers accordingly to express that.
308>
309> * To make a promise about API compatibility (which seems like the best user experience!) then start doing that and use 1.X.Y.
310> * To have the flexibility to make backwards-incompatible changes in every release but allow different parts of a large program to upgrade their code on different schedules, meaning different parts can use different major versions of the API in one program, then use X.Y.0, along with import paths like k8s.io/client/vX/foo.
311> * To make no promises about API compatible and also require every build to have only one copy of the k8s libraries no matter what, with the implied forcing of all parts of a build to use the same version even if not all of them are ready for it, then use 0.X.Y.
312
thepudds162ccfe2018-08-05 11:27:29 -0400313On a related note, Kubernetes has some atypical build approaches (currently including custom wrapper scripts on top of godep), and hence Kubernetes is an imperfect example for many other projects, but it will likely be an interesting example as [Kubernetes moves towards adopting Go 1.11 modules](https://github.com/kubernetes/kubernetes/pull/64731#issuecomment-407345841).
314
thepuddsfd489a12018-08-01 02:47:49 -0400315### Additional frequently asked questions
thepuddse01f40e2018-08-01 01:05:48 -0400316
317* Please see the earlier [FAQ from the official proposal discussion](https://github.com/golang/go/issues/24301#issuecomment-371228664), including answers to common question such as:
318 * "Won't minimal version selection keep developers from getting important updates?"
319 * "Why are major versions v0, v1 omitted from import paths?"
320 * "Why must major version numbers appear in import paths?"