gpt4 book ai didi

go - 如何避免 go.mod 文件中的间接依赖

转载 作者:行者123 更新时间:2023-12-01 21:16:08 24 4
gpt4 key购买 nike

我正在运行go build得到我的go.mod使用库更新的文件我正在使用“github.com/gocolly/colly v1.2.0”但我看到所有其他依赖项最后都说“//间接”。
如何避免得到这个?
这是我的 go.mod 文件

   module prodenv

go 1.13

require (
github.com/PuerkitoBio/goquery v1.5.1 // indirect
github.com/antchfx/htmlquery v1.2.2 // indirect
github.com/antchfx/xmlquery v1.2.3 // indirect
github.com/antchfx/xpath v1.1.5 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gocolly/colly v1.2.0
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/kennygrant/sanitize v1.2.4 // indirect
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
github.com/temoto/robotstxt v1.1.1 // indirect
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
google.golang.org/appengine v1.6.5 // indirect
)

最佳答案

不幸的是,你无法避免它们。间接依赖,基本上是未在 go.mod 中列出的依赖。您的直接依赖关系,但仍然需要它。

在您的情况下,它发生了,因为您使用 github.com/gocolly/colly v1.2.0作为依赖和v1.2.0这个包不是一个模块,因为它不包含 go.mod ,因此它的所有依赖项都是间接的,并列在您的 go.mod 中与 indirect标签。

请注意,collygo.mod在 >= v2.0.0 ,因此如果您需要该版本,这些依赖项将不会在您的 go.mod 中列为间接依赖项。 .

关于go - 如何避免 go.mod 文件中的间接依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61115111/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com