I have a project with mutliple main methods.
When running go build program1/main1.go
which has a different set of dependencies than program2/main2.go
, my first go build
seems to alter my go.mod
file and removes the dependencies it thinks it does not need. Yet main2
would need these dependencies.
I've tried using go build ...
but that also created a different set of dependencies. Specifically, it seems like all the //indirect
dependencies get removed and cause program2 to fail.
Is there a way of running go build
or go run
without updating the go.mod
file? Using go build -mod=readonly program1/main1.go
it tells me that it fails because the dependencies need to be updated..
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…