Skip to content

Support for go modules #124

@joshuarubin

Description

@joshuarubin

Beginning in go 1.11 go will have opt-in support for the vgo module system proposed by Russ Cox.

We've started testing support for this using Go tip and have run into an issue with mage.

We have a library that we use with our common mage operations. It is tagged and has a version greater than 1. As a result, its go.mod file lists the module as something like module github.com/foo/bar/v2. This means that imports of this module in the magefile would use import bar "github.com/foo/bar/v2" even though the module is downloaded (and would have been placed in the $GOPATH) at github.com/foo/bar.

The error we get when trying to compile the magefile is something like:

Error: failed to check types in directory: magefile.go:18:8: could not import github.com/foo/bar/v2 (cannot find package "github.com/foo/bar/v2" in any of:
        ~/go/src/github.com/foo/baz/vendor/github.com/foo/bar/v2 (vendor tree)
        ~/.gvm/gos/master/src/github.com/foo/bar/v2 (from $GOROOT)
        ~/go/src/github.com/foo/bar/v2 (from $GOPATH))

This stems from the fact that the stdlib go/* packages do not (and may never: golang/go#26433) support modules. The recommendation was to, instead, use the still in development golang.org/x/tools/go/packages package (which will only support Go 1.11 and later).

Until this issue is resolved, mage can't work seamlessly with go modules at all. Either we import with github.com/foo/bar in the magefile and vgo will use the latest v1 release (which is the wrong version), or we import github.com/foo/bar/v2 in the magefile and mage fails to build the magefile at all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions