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.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题