Home > Back-end >  How can I list all the import cycles in a Go project?
How can I list all the import cycles in a Go project?

Time:12-20

I'm refactoring a Go project where everything was in a single module, splitting out sub packages. Having done that, there are many import cycles. In order for the project to compile again, I have to eliminate them. However, after doing a change that I think has eliminated a cycle, the import cycle count seems to remain the same. I count the cycles with this command:

go build 2>&1 | grep package | wc -l

It keeps reporting 6 even after I do work that seems like it should have removed a cycle, and even after I no longer see the cycle I removed in the list. It makes me wonder if it's only reporting a subset of the issues.

I also tried

go build -gcflags="-e" 2>&1 | grep package | wc -l

as suggested at enter image description here

  •  Tags:  
  • go
  • Related