-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: mod tidy pulls in too many dependencies #27920
Comments
This is behaving as expected. |
go mod tidy
pulls in too many dependencies
I'm not sure I agree. That link talks about build tags and all active modules, but what happens here is that clearly inactive modules are pulled in. |
|
There is more discussion of this particular issue #27920 in a recent golang-nuts thread (also started by @alicebob, I think), where that thread might have answered at least some of the questions raised in this issue: @alicebob, in terms of your comment above about "clearly inactive modules are pulled in", the modules documentation has a particular definition for the phrase "active modules" (from https://tip.golang.org/cmd/go/#hdr-List_packages_or_modules, with emphasis added):
In any event, setting aside for the moment if you think the go tooling should behave in a different manner, do you see anywhere that |
@thepudds thanks for your replies. Yeah, I posted that to get more answers.
So I guess things work indeed mostly "as intended" :( |
I see now that vendor does not include all the modules only included in tests by vendored modules. So what's in go.mod is not simply what's added in the vendor folder, and it's smarter than that. Great! I missed that completely. It is indeed described in To answer my own initial question: yes, go.mod is long, but since that's not the list of modules which get vendored it doesn't matter. |
Here is a case which is not clear to me and I think is related to this issue: Whenever a dependency is added to the code I can just run This is how I think the majority of projects work and worked before using tools like dep and glide. Compared to this Now, I understand the reasons (I think) why it works like that, but as I said before, I don't think (the majority of) Go projects work or want to work like that. Let me give an example: It was mentioned in the google groups thread (and it is my understanding as well), that in a CI all dependencies in the go.mod files will be downloaded. This can be a huge amount of dependencies making CI builds very slow. Imagine a library providing some sort of kubernetes integration (in a separate package of the module). Even if I don't use that, the kubernetes repo will be downloaded (since it's in the project's I think in most of the cases we need a solution that keeps the go.mod an absolute minimum with the dependencies that are directly or indirectly imported during I understand that there can be cases when one would like to run tests for all the dependencies, but I also think that's probably not the majority of the projects. (Sticking to the example: I don't want to run the test suite of kubernetes) In any case, it would be nice to have an option for the above, or at least an option to limit "tidying" to removal of unused dependencies, leaving new dependencies to I may not have all the facts right, but after a few hours of reading and playing around this is what I ended up with. |
Note that “not imported anywhere else” is an expensive property to detect. That's why
In the general case, the
According to the documentation:
It's not obvious to me whether “dependencies of the main module” should refer to package dependencies or module dependencies (that's #26902), but in this case it doesn't matter, because there is an alternative that downloads only the dependencies of the main module:
which tells the |
Thanks for clarification. The only missing thing for me then is the remove functionality of tidy. Since in most of the cases I don't want to run To be honest I wonder though if I'm right about my assumption, that a majority of Go projects doesn't want to use |
@sagikazarmark This issue was closed, and as far as I am following things here, the original problem reporter seemed to indicate they were satisfied with the discussion here:
Reading over again what you wrote here, it might be a bit different than the original problem report? Would it make sense to open a new issue for what you are reporting, or do you think your open questions/issues are already covered by another set of issue(s), or is your view that this issue here should be re-opened? Sorry, just trying to see what is pending, vs. not. |
@thepudds I think I'm going to open a new issue (unless I found another one). Although I understand the explanation given in this issue, after experimenting with modules for a while I still think the behavior above is undesirable. |
What version of Go are you using (
go version
)?go version devel +38861b5127 Fri Sep 28 09:18:14 2018 +0000 linux/amd64
Does this issue reproduce with the latest release?
I did not try.
What operating system and processor architecture are you using (
go env
)?What did you do?
Make simple module which imports github.com/hashicorp/consul/api and uses go.mod.
go.mod
is good after ago build
, butgo mod tidy
will pull in everything the whole github.com/hashicorp/consul/ repo depends on, which is not needed.Make a new tiny module:
now run
go build
.go.mod
is a small list of 5 dependencies:now run
go mod tidy
, after that this isgo.mod
:most of these are not needed because the module only uses the
/api
package from consul, and it doesn't need to build the whole server. This is especially bad when vendoring.What did you expect to see?
The small version of
go.mod
What did you see instead?
The huge version of
go.mod
The text was updated successfully, but these errors were encountered: