英文:
How to detect deprecated direct dependencies in a pipeline for a go project
问题
我正在尝试检测Go项目中的直接废弃依赖项。为此,我创建了一个名为deptest的虚拟项目,它有一个名为depricon的直接依赖项。根据go1.17发布说明中的模块废弃注释部分,可以通过go list -m -u
命令获取废弃的依赖项。但是,当我在我的项目中运行该命令时,我得到的结果是:
$ go list -m -u
github.com/zbindenren/deptest
我只能通过以下命令看到废弃警告:
$ go get ./...
go: module github.com/zbindenren/depricon is deprecated: This module is not maintained anymore.
或者通过:
$ go list -m -u all
github.com/zbindenren/deptest
github.com/zbindenren/depricon v0.0.1 (deprecated)
但是,使用第二个命令,我还会得到所有间接废弃的依赖项。
我的问题是:go list -m -u
不显示废弃模块,这是一个错误吗?是否有比运行go get ./...
更好的方法来检查废弃模块?
英文:
I am trying to detect direct deprecated dependencies in a go project. For that I created the a dummy project deptest which has depricon direct dependency. As stated in go1.17 release notes under the Module deprecation comments section it should be possible to get the deprecated dependencies with go list -m -u
. But when I run the command in my project I get:
$ go list -m -u
github.com/zbindenren/deptest
I see the deprecation warning only with the following commands:
$ go get ./...
go: module github.com/zbindenren/depricon is deprecated: This module is not maintained anymore.
Or with:
$ go list -m -u all
github.com/zbindenren/deptest
github.com/zbindenren/depricon v0.0.1 (deprecated)
But with the second command I also get all indirect deprecateded dependencies.
My question is: is this a bug that go list -m -u
doesn't show the deprecated modules? And is there maybe a better way to check for deprecated modules than running go get ./...
?
答案1
得分: 3
首先,当你运行go list -m -u
而没有指定模块参数时,它只会列出主模块(来源):
> -m
标志使得go list
列出模块而不是包。[...] 如果没有指定参数,将列出主模块。
然后,Go 1.17的发布说明实际上指出:
> go list -m -u
会打印出所有依赖项的弃用信息(使用-f
或-json
来显示完整的消息)
因此,使用包含已弃用依赖项的模块参数运行,并指定格式:
$ go list -m -u -f '{{.Path}} {{.Deprecated}}' all
github.com/zbindenren/deptest
github.com/zbindenren/depricon This module is not maintained anymore.
如果你只想限制输出为直接依赖项,可以使用模板技巧:
$ go list -m -u -f '{{if not .Indirect}}{{.Path}} {{.Deprecated}}{{end}}' all
或者等待这个提案的实施。
英文:
First, when you run go list -m -u
without a module argument, it lists only the main module (source):
> The -m flag causes go list to list modules instead of packages. [...] If no arguments are specified, the main module is listed.
Then, the release notes of Go 1.17 actually state that:
> go list -m -u
prints deprecations for all dependencies (use -f or -json to show the full message)
So run with a module argument that includes your deprecated dependency, and specify the format:
$ go list -m -u -f '{{.Path}} {{.Deprecated}}' all
github.com/zbindenren/deptest
github.com/zbindenren/depricon This module is not maintained anymore.
If you want to limit output to only direct dependencies, use a template trick:
$ go list -m -u -f '{{if not .Indirect}}{{.Path}} {{.Deprecated}}{{end}}' all
Or wait for this proposal to come through.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论