Closed heartless-clown closed 2 years ago
The way I have been avoiding conflicting deps when using go.work
was to run go work sync
to ensure that all the go.mod and go.sum files are in synced. 🤔 https://github.com/sluongng/nogo-analyzer/blob/master/tools/BUILD.bazel#L3-L13
So my workflow is usually something like:
code --> run gazelle --> run buildifier
if dep changes
--> run go mod tidy in package
--> run go work sync in workspace
--> run gazelle update-repos
--> (optionally) run deps pruner (a custom tool i made to trim down unused go_repository)
This helps avoid all conflicting deps. Note how all these are quite manual today, I do plan to automate most of these, at least for this repository... but I am currently being blocked by a different effort in improving rules_go's bazel runfiles
library first.
As regarding staticcheck version confusion, in a very early iteration of this repository (when I submitted this to rules_go and was adviced to create a separate repo instead), I did included this line:
Note that loading staticcheck_deps() is completely optional, advance users may want to manage their own staticcheck dependencies separately in your WORKSPACE file.
Perhaps we need to bring it back and give folks some example of simple setup? 🤔
Bazel's WORKSPACE load order could get very confusing which is why I remember this handy command:
> bazel query '//external:co_honnef_go_tools' --output=build
which helps validate which version is being used by the current workspace. I guess we can document this as well 🤔
Initially I proposed #14 as an attempt to solve this:
If your repo loads
go_repository
rules with outdated versions of staticcheck dependencies, your build fails with error like this one:Note that
go_deps()
rule that contains the outdated version ofco_honnef_go_tools
was placed after thestaticcheck_deps()
.Here is the example repo:
With the following commits:
Also here is the branch that sets up minimal test for dependency conflict: