Cherry-pick #15853 to 7.x: Go modules #16748
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cherry-pick of PR #15853 to 7.x branch. Original message:
This PR introduces the new dependency management system for beats. From now on we are using
go mod
instead ofgovendor
. The name of the module we provide is namedgithub.com/elastic/beats/v7
.We adopted go modules, but we still keep dependencies under the folder
vendor
. However, it is maintained bygo mod
now by runningmage vendor
. Thus, it is not possible to add local changes to the dependencies there because next time someone runs the command it will be overwritten. If you need to apply patches to dependencies either fork the repository or try to contribute it back to the original repo.This PR does not address the changes in Beat generators. Those are going to be updated in a follow-up PR.
FAQ
How can I add a new dependency?
TL;DR
Run
go get {{ module_name }}@{{ required_version }}
in the repository. This adds the module to the requirements list ingo.mod
. In order to add the dependency to the vendor folder, runmage vendor
. If the dependency contains files which are not copied by this command (e.g. C source files), add them to this list: https://github.com/elastic/beats/tree/master/dev-tools/mage/gomod.goHow can I upgrade a dependency?
The process is similar to adding a new dependency. Except for one step. If the dependency is updated to a newer major version, make sure to follow up changes in the root import paths of those libs. I suggest using the tool named
mod
to upgrade it: https://github.com/marwan-at-work/modHow can I use a fork of a dependency?
If you need to use a fork of a dependency, add it to
go.mod
either manually or by running the following command:Why is the major version part of the import path?
In a nutshell, it is needed to tell apart major version changes. Their import paths are different because those are incompatible. See more: https://blog.golang.org/v2-go-modules
Thus, when we are releasing v8.0.0, we need to change the import path again. The tool named mod is going to be useful for us in this case, too.
Why is
make check
failing?Are you seeing the following error?
If your
go.mod
listsgithub.com/elastic/beats
as a requirement, the repo contains an outdated root import path. Changegithub.com/elastic/beats
togithub.com/elastic/beats/v7
.What is next?
After this PR is merged, please rebase all of your open PRs. In most cases rebasing will lead to conflicts. Possible sources of conflicts:
github.com/elastic/beats
import togithub.com/elasitc/beats/v7
.Further reading for the interested
Related issues
#15868