Welcome to Golang Bridge!
Unfortunately, this is not a simple question but don’t worry about it.
If you’re using module, you should not use
vendor anymore. It confuses everyone. Hence, the goal is to
go build without the
Depending on urgency, I propose 2 ways.
Short Term Mitigation
vendor has 1 main effect on overall repository that requires consideration: it influences the local import across the source codes. E.g.:
- Instead of importing the package like
import "github.com/XYZ/abc", placing that package in
vendor/abc allows the source codes to import package like
Hence, we need to workaround it. Fortunately,
go.mod has a
replace clause for you to replace any import clause in your source codes to a local directory. Based on the example above,
abc => ./vendor/abc
Once you replace all the
vendor dependencies accordingly, test run again without the
mod=vendor argument. If everything works fine, you’re good to go for now.
Long Term Migration
For long term migrations, you need to change the source codes
import clauses back to its original repository point. This will eliminate the dependency on
vendor remote packages. As for non-remote
vendor packages, you can create an independent module repository for it and import back to the project.
When I say long term, it means it takes time for the migration depending on the size of the repository and how widespread the vendor import statements in all the source codes. Consider it a refactor effort.