Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid indirect dependencies in go.mod file

Tags:

go

I am running go build to get my go.mod file updated with library I am using "github.com/gocolly/colly v1.2.0" But I see all other dependencies saying "// indirect" at end. How to avoid getting this? Here is my go.mod file

   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
)
like image 498
Raj Avatar asked Apr 09 '20 06:04

Raj


People also ask

What is indirect in Go mod file?

The go command automatically adds // indirect comments for some requirements. An // indirect comment indicates that no package from the required module is directly imported by any package in the main module.

What are indirect dependencies?

A deep (indirect) dependency is a package that you are not using directly, but one that is used by one of your direct dependencies. For example, if your application is using package A, and package A is using package B, then your application is indirectly depending on package B.

What does indirect mean in go?

Indirect – It is the dependency that is imported by the module's direct dependencies. Also, any dependency that is mentioned in the go. mod file but not imported in any of the source files of the module is also treated as an indirect dependency.


1 Answers

Unfortunately, you can't avoid them. Indirect dependency, is basically dependency that wasn't listed in go.mod of your direct dependency, but is still required by it.

In your case it happens, because you use github.com/gocolly/colly v1.2.0 as dependency and v1.2.0 of this package isn't a module, because it doesn't contain go.mod, so all it's dependencies are indirect and listed in your go.mod with indirect tag.

Note, that colly has go.mod in >=v2.0.0, so if you require that version, these dependencies won't be listed as indirect in your go.mod.

like image 98
Grigoriy Mikhalkin Avatar answered Sep 20 '22 02:09

Grigoriy Mikhalkin