日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

執(zhí)行g(shù)o?vendor第三方包版本沖突問(wèn)題解決_Golang

作者:Airy ? 更新時(shí)間: 2022-09-08 編程語(yǔ)言

問(wèn)題癥狀

我們使用 jenkins 腳本執(zhí)行 go build ,用來(lái)構(gòu)建線上服務(wù)器使用的二進(jìn)制文件。構(gòu)建過(guò)程中有這樣一個(gè)步驟:

go mod vendor

該步驟將以 go.mod 文件中寫(xiě)明的包和版本為準(zhǔn)下載第三方依賴并保存到本地的 vendor 目錄。下載過(guò)程中將校驗(yàn) go.sum 中的 hash 值是否同文件 hash 一致。

在實(shí)際執(zhí)行中,遇到這樣的錯(cuò)誤:

internal error: failed to find embedded files of github.com/marten-seemann/qtls-go1-18: //go:build comment without // +build comment

排查經(jīng)過(guò)

通過(guò) qtls-go1-18 的倉(cāng)庫(kù)名可以觀察到問(wèn)題可能跟 go 1.18 的版本有關(guān)。

打開(kāi)依賴的 github 倉(cāng)庫(kù)可見(jiàn)簡(jiǎn)介:

Go standard library TLS 1.3 implementation, modified for QUIC. For Go 1.18.

而我們構(gòu)建的環(huán)境 go env 輸出的版本為 1.16

在 go 1.18 的?release notes?中查找相關(guān)信息:

//go:build lines
Go 1.17 introduced //go:build lines as a more readable way to write build constraints, instead of // +build lines. As of Go 1.17, gofmt adds //go:build lines to match existing +build lines and keeps them in sync, while go vet diagnoses when they are out of sync.

Since the release of Go 1.18 marks the end of support for Go 1.16, all supported versions of Go now understand //go:build lines. In Go 1.18, go fix now removes the now-obsolete // +build lines in modules declaring go 1.18 or later in their go.mod files.

報(bào)錯(cuò)的意思是?//go:build?(1.18 版本支持) 必須同?// +build?一起出現(xiàn)。至此確認(rèn)問(wèn)題原因。

解決辦法

業(yè)務(wù)代碼并沒(méi)有直接用到 qtls 包,且并沒(méi)有直接依賴 qtls-go1-18 對(duì)應(yīng)的 go 版本。此庫(kù)為非直接依賴引入的,需要找出是那個(gè)包引入了這個(gè)依賴。

go mod why github.com/marten-seemann/qtls-go1-18

可以查看是誰(shuí)引入該依賴。從輸出可以看到:

# github.com/marten-seemann/qtls-go1-18
git.mycompany.com/group/projecta
git.mycompany.com/group/projectb
github.com/smallnest/rpcx/client
github.com/lucas-clemente/quic-go
github.com/marten-seemann/qtls-go1-18

通過(guò)?go mod graph?可以看到具體那個(gè)包的那個(gè)版本引入的

最終確認(rèn)是 quic-go 的 0.27 引入的。

在 go.mod 中排除掉 quic-go 0.27 即可。在 go.mod 中加一行。

exclude lucas-clemente/quic-go v0.27.0

總結(jié)和其他

  • 為什么 go mod vendor 會(huì)更新版本,理論上只會(huì)使用 go.mod 中制定的版本;
  • build 機(jī)器不需要 go mod vendor ,直接 go mod download 即可;
  • go mod vendor 同 go mod download 在依賴管理上有什么不同?

原文鏈接:https://segmentfault.com/a/1190000042108758

欄目分類(lèi)
最近更新