AJR
AJR

Reputation: 1681

go.mod replace directive is ignored

I'm using the Go thrift package from Apache, which is at lib/go/thrift in the Git repo at git.apache.org/thrift.git. This is the import statement:

import "git.apache.org/thrift.git/lib/go/thrift"

This works fine for using the official Apache code but we needed to make a change to the Apache code so I just added a replace directive to the go.mod file for the project to pick up our changed version of the package:

replace git.apache.org/thrift.git/lib/go/thrift => <local_path>/lib/go/thrift

where <local_path> is where the (patched) git repo was saved. I added a go.mod file to this location (<local_path>/lib/go/thrift) simply containing this:

module git.apache.org/thrift.git/lib/go/thrift

go 1.12

However the Go compiler ($ go build) insists on downloading and using the Apache package and is ignoring the replace directive. Any ideas on the cause of this problem?

Upvotes: 2

Views: 2888

Answers (1)

AJR
AJR

Reputation: 1681

The fix I found (after much experimenting) is to remove the go.mod file from <local_path>/lib/go/thrift (this step was essential) and add this go.mod file to <local_path>:

module git.apache.org/thrift.git

go 1.12

Plus also change the replace directive to remove the lib/go/thrift part like this:

replace git.apache.org/thrift.git => <local_path>

The import statement was unchanged.

Upvotes: 3

Related Questions