Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing a go module fails with `invalid: module contains a go.mod file, so major version must be compatible`

Tags:

go

jenkins-x

I'm trying to import from Jenkins-X/jx to customize some stuff a little bit.

I'm really new to go heads up

but trying to go get ./... fails.

my go.mod file

module github.com/my-org/my-project

go 1.13

require github.com/jenkins-x/jx v2.0.383

I get

... require github.com/jenkins-x/jx: version "v2.0.383" invalid: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2

which is because jx has a few requirements in its mod file

But I'm not sure what I have to do to actually download the module.

like image 270
Benbentwo Avatar asked Sep 23 '19 16:09

Benbentwo


People also ask

How do I download a go module with an error?

If an error occurs, the result will be a Module struct with a non-nil Error field. The go mod download command downloads the named modules into the module cache. Arguments can be module paths or module patterns selecting dependencies of the main module or version queries of the form path@version.

Why am I getting a module version error when trying to import?

This error happens when you attempt to fetch a module that has a major version equal or higher than v2, but either their own go.mod file, or your import path are missing the necessary /vN suffix. If the module is version v2 or higher, the major version of the module must be included as a /vN at the end of the module paths used in go.mod files

How are Go modules defined?

Each Go module is defined by a go.mod file that describes the module’s properties, including its dependencies on other modules and on versions of Go. These properties include:

What is the correct module path for GO command?

To preserve import compatibility, the go command requires that modules with major version v2 or later use a module path with that major version as the final element. For example, version v2.0.0 of example.com/m must instead use module path example.com/m/v2.


1 Answers

To anyone looking to compile with some neat Jenkins-x functions I was able to talk to the creators and found out a few things.

  1. Go 1.12.4
  2. Look at their lighthouse project which has a go.mod and uses jenkins-x/jx as a requirement
  3. As mentioned in the comments once a project goes above major version 1 essentially go.mod uses 0.0.0-timestamp-commithash
like image 97
Benbentwo Avatar answered Sep 17 '22 09:09

Benbentwo