Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go.mod file got overridden after go build #32332

Closed
SVilgelm opened this issue May 30, 2019 · 9 comments
Closed

cmd/go: go.mod file got overridden after go build #32332

SVilgelm opened this issue May 30, 2019 · 9 comments
Labels

Comments

@SVilgelm
Copy link

@SVilgelm SVilgelm commented May 30, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/svilgelm/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/svilgelm/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.5/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/svilgelm/Library/Mobile Documents/com~apple~CloudDocs/workspace/k8ss/iam_api/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/9x/_3ch6yp158dcsmh8b_4f17tr0000gn/T/go-build142036667=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I'm trying to add gocloak module to mine as a dependency but something strange happens. Can you please explain to me what I'm doing wrong and why this is the result?

add the import in my go file like this
import "github.com/Nerzal/gocloak"

add this to my go.mod file
require github.com/Nerzal/gocloak v2.0.0

I build with go build and my go.mod file got overridden like this
require github.com/Nerzal/gocloak v0.0.0-20190525151100-dfd1e50572f8

What did you expect to see?

require github.com/Nerzal/gocloak v2.0.0

What did you see instead?

require github.com/Nerzal/gocloak v0.0.0-20190525151100-dfd1e50572f8

@SVilgelm

This comment has been minimized.

Copy link
Author

@SVilgelm SVilgelm commented May 30, 2019

the github.com/Nerzal/gocloak repo has v2.0.0 tag, but the go build/test always override the version in go.mod file to v0.0.0-20190525151100-dfd1e50572f8

@triztian

This comment has been minimized.

Copy link

@triztian triztian commented May 30, 2019

If you do not wish to for your go.mod to be updated, you can do a build using the -mod=readonly flag, i.e.:

go build -mod=readonly .

You can also use vendored deps, by using the vendor mod flag:

go build -mod=vendor .
@SVilgelm

This comment has been minimized.

Copy link
Author

@SVilgelm SVilgelm commented May 30, 2019

Thanks, but why the versions of other packages are not changed? Build changes only the line with gocloak.

require (
	github.com/DATA-DOG/godog v0.7.13
	github.com/Nerzal/gocloak v0.0.0-20190525151100-dfd1e50572f8
	github.com/dgrijalva/jwt-go v3.2.0+incompatible
	github.com/golang/mock v1.3.1
	github.com/golang/protobuf v1.3.1
	github.com/google/uuid v1.1.1
	github.com/grpc-ecosystem/go-grpc-middleware v1.0.0
	github.com/inconshreveable/mousetrap v1.0.0 // indirect
	github.com/mattn/go-runewidth v0.0.4 // indirect
	github.com/mitchellh/go-homedir v1.1.0
	github.com/olekukonko/tablewriter v0.0.1
	github.com/spf13/cobra v0.0.3
	github.com/spf13/pflag v1.0.3
	github.com/spf13/viper v1.3.2
	golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f
	golang.org/x/lint v0.0.0-20190409202823-959b441ac422 // indirect
	golang.org/x/net v0.0.0-20190522155817-f3200d17e092
	golang.org/x/sys v0.0.0-20190529130038-5219a1e1c5f8 // indirect
	golang.org/x/text v0.3.2 // indirect
	golang.org/x/tools v0.0.0-20190529010454-aa71c3f32488 // indirect
	google.golang.org/grpc v1.20.1
	gopkg.in/resty.v1 v1.12.0
	gopkg.in/yaml.v2 v2.2.2
)
@triztian

This comment has been minimized.

Copy link

@triztian triztian commented May 30, 2019

On possible reason could be because you have gocloak set to v2 in go.mod and your import statement does not have a v2 suffix then go build assumes uses the latest commit that is a <2 version and updates the go.mod to point to that commit and version, one solution would be to change your imports from:

import "github.com/Nerzal/gocloak"

to

import "github.com/Nerzal/gocloak/v2"

This is documented here:

@SVilgelm

This comment has been minimized.

Copy link
Author

@SVilgelm SVilgelm commented May 30, 2019

build iam/pkg/cmd/iam_api: cannot load github.com/Nerzal/gocloak/v2: cannot find module providing package github.com/Nerzal/gocloak/v2

Why build doesn't override the github.com/DATA-DOG/godog v0.7.13or github.com/dgrijalva/jwt-go v3.2.0+incompatible lines? We import these packages without v0 or v3 suffixes

@triztian

This comment has been minimized.

Copy link

@triztian triztian commented May 30, 2019

Update your go.mod file package to also have v2 suffix, when the package version is below 2 then package suffixes are not needed, i.e., in go.mod:

require github.com/Nerzal/gocloak/v2 v2.0.0

May I recommend opening a help topic in the golang forums?, it seems like this is not an issue with the go project.

I'll follow up there when time permitting, the forums can be located here:

@mdempsky mdempsky changed the title go.mod file got overridden after go build cmd/go: go.mod file got overridden after go build May 30, 2019
@thepudds

This comment has been minimized.

Copy link

@thepudds thepudds commented May 31, 2019

I think the reason this is happening is because github.com/Nerzal/gocloak is a v2 module, but is missing the required /v2 at the end of its module statement in its go.mod:

https://github.com/Nerzal/gocloak/blob/v2.0.1/go.mod#L1

I'd suggest opening an issue on that repository.

#31543 and other issues cover making this a bit clearer. (See "Factor 2" section in #31543 for a bit more).

CC @tbpg @jayconrod @bcmills

@thepudds thepudds added the modules label May 31, 2019
@tbpg

This comment has been minimized.

Copy link
Contributor

@tbpg tbpg commented May 31, 2019

Why build doesn't override the github.com/DATA-DOG/godog v0.7.13or github.com/dgrijalva/jwt-go v3.2.0+incompatible lines? We import these packages without v0 or v3 suffixes

v0 and v1 packages do not require the major version suffix to import/use them. However, once you get beyond v2, you have to include the major version.

This is a new requirement, so in order to facilitate backwards compatibility with repos that already had v2+ tags, Go supports +incompatible on the version. This makes it so you can use a v2+ tag even if the repository doesn't follow semantic import versioning. Once you create a module for the repo, it should follow the semantic import versioning (SIV) rule, or you end up with the pseudo-version you see in this issue.

The gocloak repo is not following this rule right now. Go should make it easier to understand, find, and prevent this error, as @thepudds pointed out.

I think we can close this issue in favor of #31543.

@SVilgelm

This comment has been minimized.

Copy link
Author

@SVilgelm SVilgelm commented May 31, 2019

Guys, thank you so much for the help, it's little bit unclear

@SVilgelm SVilgelm closed this May 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.