網站首頁 編程語言 正文
問題癥狀
我們使用 jenkins 腳本執行 go build ,用來構建線上服務器使用的二進制文件。構建過程中有這樣一個步驟:
go mod vendor
該步驟將以 go.mod 文件中寫明的包和版本為準下載第三方依賴并保存到本地的 vendor 目錄。下載過程中將校驗 go.sum 中的 hash 值是否同文件 hash 一致。
在實際執行中,遇到這樣的錯誤:
internal error: failed to find embedded files of github.com/marten-seemann/qtls-go1-18: //go:build comment without // +build comment
排查經過
通過 qtls-go1-18 的倉庫名可以觀察到問題可能跟 go 1.18 的版本有關。
打開依賴的 github 倉庫可見簡介:
Go standard library TLS 1.3 implementation, modified for QUIC. For Go 1.18.
而我們構建的環境 go env 輸出的版本為 1.16
在 go 1.18 的?release notes?中查找相關信息:
//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.
報錯的意思是?//go:build
?(1.18 版本支持) 必須同?// +build
?一起出現。至此確認問題原因。
解決辦法
業務代碼并沒有直接用到 qtls 包,且并沒有直接依賴 qtls-go1-18 對應的 go 版本。此庫為非直接依賴引入的,需要找出是那個包引入了這個依賴。
go mod why github.com/marten-seemann/qtls-go1-18
可以查看是誰引入該依賴。從輸出可以看到:
# 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
通過?go mod graph
?可以看到具體那個包的那個版本引入的
最終確認是 quic-go 的 0.27 引入的。
在 go.mod 中排除掉 quic-go 0.27 即可。在 go.mod 中加一行。
exclude lucas-clemente/quic-go v0.27.0
總結和其他
- 為什么 go mod vendor 會更新版本,理論上只會使用 go.mod 中制定的版本;
- build 機器不需要 go mod vendor ,直接 go mod download 即可;
- go mod vendor 同 go mod download 在依賴管理上有什么不同?
原文鏈接:https://segmentfault.com/a/1190000042108758
相關推薦
- 2022-06-25 C#設計模式之適配器模式與裝飾器模式的實現_C#教程
- 2023-01-20 Go語言實現定時器的原理及使用詳解_Golang
- 2022-11-02 Qt5.14.2使用虛擬鍵盤的關鍵代碼_C 語言
- 2023-02-05 scipy.interpolate插值方法實例講解_python
- 2024-07-15 解決`idea`中`database`工具查詢起別名亂碼問題
- 2022-03-30 C++?Qt?QColorDialog使用方法_C 語言
- 2022-10-03 Pandas數據集的分塊讀取的實現_python
- 2023-06-02 Hadoop部署的基礎設施操作詳解_服務器其它
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支