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: replace directive for go modules does not work recursively #38665

Closed
ghost opened this issue Apr 26, 2020 · 3 comments
Closed

cmd/go: replace directive for go modules does not work recursively #38665

ghost opened this issue Apr 26, 2020 · 3 comments
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ghost
Copy link

ghost commented Apr 26, 2020

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

1.14

Does this issue reproduce with the latest release?

YES

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

Linux, AMD64

What did you do?

I have the directory structure as follows:

top-dir/
|-- module1
|   |-- go.mod
|   `-- test.go
|-- module2
|   |-- go.mod
|   `-- test.go
`-- module3
    |-- go.mod
    `-- test.go

3 directories, 6 files

File module1/go.mod:

module company.com/module1

go 1.14

replace company.com/module2 => ../module2

require company.com/module2 v0.0.0

File module1/test.go:

package main

import "company.com/module2"

func main() {
	module2.Test()
}

File module2/go.mod:

module company.com/module2

go 1.14

replace company.com/module3 => ../module3

require company.com/module3 v0.0.0

File module2/test.go:

package module2

import "company.com/module3"

func Test() {
	println("this is company.com/module2")
	module3.Test()
}

File module3/go.mod:

module company.com/module3

go 1.14

File module3/test.go:

package module3

func Test() {
	println("this is company.com/module3")
}

Summary:
module1 depends on a local module module2, and module2 depends on another local module module3. I use replace directive in the two go.mod files in module1 and module2.

What did you expect to see?

When I try go build in module1, it is expected that the compiler find module2 and module3 in the local filesystem, rather than fetching them from a remote server.

What did you see instead?

The go compiler succeeded in figuring out the right source of module2 (in local directory top-dir/module2), but failed for module3. It attempted to fetch module3 from the server company.com:

go: company.com/module2@v0.0.0 requires
	company.com/module3@v0.0.0: unrecognized import path "company.com/module3": https fetch: Get "https://company.com/module3?go-get=1": x509: certificate signed by unknown authority
@magical
Copy link
Contributor

magical commented Apr 26, 2020

This is by design. Only replace directives in the top-level go.mod are considered during the build.

@andybons andybons changed the title replace directive for go modules does not work recursively cmd/go: replace directive for go modules does not work recursively Apr 27, 2020
@andybons andybons added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Apr 27, 2020
@andybons andybons added this to the Unplanned milestone Apr 27, 2020
@andybons
Copy link
Member

Adding @bcmills @jayconrod @matloob to confirm if it’s by design or not.

@bcmills
Copy link
Contributor

bcmills commented Apr 27, 2020

This is by design. Per go help go.mod:

Exclude and replace apply only in the main module's go.mod and are ignored in dependencies. See https://research.swtch.com/vgo-mvs for details.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants