For legal reasons, I need a list of licenses (e.g. MIT, Apache) the dependencies (direct and transient libraries) my project uses. I only know how to print a list of dependencies without licenses.
Is there a way to print a list of dependencies with licenses for Go Modules? Similar to what is done in npm (NPM License Checker) and Gradle (Gradle License Report). Thanks!
1 Answer
Have you tried
Run
go get -v go build ./go-licenses csv . That gives you some information at least.
A bit more verbosity: So I create a test project:
package main import ( "encoding/json" "fmt" log "" ) func main() { log.Warn("Warn") foo := make(map[string]bool) foo["bar"] = true j, _ := json.MarshalIndent(foo, " ", " ") fmt.Println(string(j)) } The I do:
me@dattan:~/testing/blabla$ go mod init go: creating new go.mod: module me@dattan:~/testing/blabla$ go build go: finding module for package go: downloading v1.5.0 go: found in v1.5.0 go: downloading v0.0.0-20190422165155-953cdadca894 me@dattan:~/testing/blabla$ go get -v go: downloading v0.0.0-20200227160636-0fa8c766a591 ... [lots of downloads, that's why -v to see it's not dead] me@dattan:~/testing/blabla$ go build me@dattan:~/testing/blabla$ ./go-licenses csv . E0406 23:03:48.578291 32389 library.go:108] Failed to find license for no file/directory matching regexp "^(LICEN(S|C)E|COPYING|README|NOTICE)(\\..+)?$" found for /home/me/testing/blabla E0406 23:03:48.627889 32389 csv.go:84] Error discovering URL for "/home/me/go/pkg/mod/[email protected]/LICENSE": - unsupported package host "golang.org" for "" And those last lines there, not perfect but it does see that logrus is MIT and provide the link to the license. My test package lacking a LICENSE file fails of course.
Edit from comment While the above worked for me these are the commands the asker needed to do:
go build ./... ./go-licenses csv ./... 8