Go.mod exclude specific packages when 'go mod vendor'

Is the somepackage a module or classical GOPATH package?

Basically, replace clause it aliasing the github.com/somepackage import keyword to a local directory or another package module. In other word, you can git clone the somepackage next to your project, in a file directory like:

root
  +---myProject
  |        + go.mod
  |        + ...
  +---somePackage
           + go.mod?
           + ...

or the vendor packages inside myProject.

Then, inside myProject/go.mod, your replace clause would be:

replace github.com/somepackage => ../somePackage

So go will seek out the local directory for github.com/somepackage module.

Also, you do not have to point towards the $GOPATH/pkg/mod directory manually because that is go module’s working directory. If that’s something you’re looking for, then the replace clause would be:

replace github.com/somepackage/aa/cc => github.com/anotherPackage/aa/cc vX.Y.Z

If all else still fails, you might need to do vendor-module migrations for specific vendor package/subpackage.

More info:

  1. replace clause:
  1. Module and Vendor
2 Likes