douqiandai4327 2018-12-06 15:55
浏览 314

golang模块无法将单个依赖项更新到我的.mod文件

I want to update a single dependency in my modules repo.

I've looked through lots of documentation and the JustForFunc videos and it seems like the way to do this is go into the .mod file and update from "1.0.0" to "1.2.0" and run go build.

This works, but then I see my entire go.mod file changed in many places, including those that are not indirects. Some of these changed versions are major version changes for dependencies used in other places in my project. My obvious fear is this will cause a breaking change when I want these versions to remain the same.

I'm using modules and working outside my GOPATH if that matters.

Is there a way to minimize my .mod file changes?

  • 写回答

1条回答 默认 最新

  • duanlijia5864 2018-12-06 16:00
    关注

    tl;dr pass -mod=readonly to go commands to prevent it from automatically updating dependencies to the latest minor/patch releases.

    Per the Go wiki:

    To upgrade or downgrade to a more specific version, 'go get' allows version selection to be overridden by adding an @version suffix or "module query" to the package argument, such as go get github.com/gorilla/mux@v1.6.2, go get foo@e3702bed2, or go get foo@'

    And from the same wiki:

    The go tooling provides a fair amount of flexibility to adjust or disable these default behaviors, including via -mod=readonly, -mod=vendor, GOFLAGS, GOPROXY=off, GOPROXY=file:///filesystem/path, go mod vendor, and go mod download.

    The details on these options are spread throughout the official documentation. One community attempt at a consolidated overview of knobs related to these behaviors is here, which includes links to the official documentation for more information.

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大