英文:
How to determine which module/s use an indirect dependency?
问题
在Go 1.17中,go.mod文件有两个部分,直接依赖和间接依赖。然而,并没有说明间接依赖与直接依赖之间的关系。
我如何找出特定的间接依赖被哪个模块或哪些模块使用?
英文:
In Go 1.17 go.mod has two sections, direct dependencies and indirect dependencies, however, there is no indication how indirect dependencies are related to direct dependencies.
How can I find out for a particuar indirect dependency what module or modules use it?
答案1
得分: 27
go mod why -m $MODULE
将为您提供从您的模块中的一个包到$MODULE
中的一个包的一条(任意选择的)导入链。然而,它并不会原生地报告所有这样的路径。
go list -json all
提供了足够的信息来识别这些路径,但它并没有提供一种简单的方式来呈现供人阅读的导入链。然而,一些第三方工具(如goda
和gomod
)可以将go list
的输出转换或查询为更结构化的形式。(请参阅它们的文档以了解查询语法和示例。)
英文:
go mod why -m $MODULE
will give you one (arbitrarily-chosen) chain of imports from a package in your module to a package in $MODULE
. However, it does not natively report all such paths.
go list -json all
does expose enough information to identify those paths, but it does not provide an easy way to present import chains for human consumption. However, some third-party tools (such as goda
and gomod
) can transform or query the output from go list
with more structure. (See their documentation for query syntax and examples.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论