Showing effective replace in go modules

142 views
Skip to first unread message

Amit Saha

unread,
Jul 30, 2021, 12:54:44 AM7/30/21
to golang-nuts
Say, i have a module A (github.com/username/foo/v1) with a replace of
a third-party package in its go.mod:

replace github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt
v3.2.1+incompatible

Now, i require module A/v1 package from module A in my module B
containing the main package:

require (
github.com/username/foo/v1
)

I want to make sure that, in my module B, "github.com/golang-jwt/jwt
v3.2.1" is pulled in.

I could verify that using the https://github.com/Helcaraxan/gomod tool:

$ ~/go/bin/gomod reveal | grep jwt
'github.com/dgrijalva/jwt-go' is replaced:
github.com/launchdarkly/ld-relay/v6 -> github.com/golang-jwt/jwt @
v3.2.1+incompatible

Is there a way to verify the above using one of the go mod or go
build/list commands?

Thanks,
Amit.

Jay Conrod

unread,
Jul 30, 2021, 11:33:45 AM7/30/21
to Amit Saha, golang-nuts
The go command only applies replace directives from the main module's go.mod file. In this example, replace directives in your module B would be applied, but replace directives in A (or any other dependency) would be ignored. This is important for avoiding conflicts that can't easily be resolved (for example, you depend on X and Y, and they both depend on incompatible forked versions of Z).

The command 'go list -m -json $modulepath' shows information about any module you depend on. In the output, the Replace field will be set if the module is replaced.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CANODV3kGLUnA0cz_NTBZnYL5%2BrO7rec4WD6FvBqz9ohfNLMMRw%40mail.gmail.com.

Amit Saha

unread,
Aug 1, 2021, 9:00:34 PM8/1/21
to Jay Conrod, golang-nuts
On Sat, Jul 31, 2021 at 1:32 AM Jay Conrod <jayc...@google.com> wrote:
>
> The go command only applies replace directives from the main module's go.mod file. In this example, replace directives in your module B would be applied, but replace directives in A (or any other dependency) would be ignored. This is important for avoiding conflicts that can't easily be resolved (for example, you depend on X and Y, and they both depend on incompatible forked versions of Z).
>
> The command 'go list -m -json $modulepath' shows information about any module you depend on. In the output, the Replace field will be set if the module is replaced.

Thanks for clearing my confusion as well as the pointer to go list for
showing the data i am looking for.

For someone else looking for the exact command: go list -m -f
'{{.Path}} => {{.Replace}}' is one way to verify this.
Reply all
Reply to author
Forward
0 new messages