protobuf.mod Reference
Specification for protobuf.mod, the tool-neutral DSL for defining Protocol Buffer module identities, roots, requirements, and local replace directives.
The protobuf.mod file resides at the root of a Protocol Buffer module. Designed as a tool-neutral standard, it contains zero tool-specific settings (no linter flags, generator plugins, or vendor extensions). It is strictly focused on module identity, inner root directories, dependency requirements, and local source overrides.
DSL Syntax & Directives
Prop
Type
Example Specification
// proto/user/protobuf.mod
module github.com/acme/user
roots (
proto
)
require (
github.com/googleapis/googleapis v1.5.0
github.com/acme/weather v1.2.3
github.com/acme/gateway/v2 v2.19.0 // indirect
)
// Local debug replacement
replace github.com/acme/weather => ../weather-forkBehavior Rules
- Git-Native Identity: The canonical identity of a module is its Git URL (e.g.,
github.com/acme/weather). - Per-Module Bounds: Every module maintains its own independent
protobuf.mod. MVS operates per-module rather than forcing global monorepo single-version constraints. - Local replacements: Only main-module directives apply, including to transitive requirements; dependency-owned replacements are ignored. A replacement alone does not introduce a module. With
replace, commands use a local effective graph and preserveprotobuf.lockbyte-for-byte; a missing lock is not created.mod tidyalso leaves the manifest unchanged.getandmod updatemay edit explicit requirements without adding fork-only transitives.mod downloadinstalls only needed unreplaced snapshots. Remove replacements and runmod tidyto produce a publishable lock. See local replacements.
For multiple modules, place a protobuf.mod in each module directory. Module commands and get select the nearest ancestor manifest within the workspace; each module keeps its own protobuf.lock. generate.modules selects local modules by identity or workspace-relative path. A consumer declares each nested Git module separately by its manifest identity.
A version may be omitted, for example require github.com/acme/contracts/proto/user. This adds no constraint if the graph already supplies a SemVer or exact commit. Only a still-unconstrained requirement uses the existing lock pin during tidy, or current HEAD without a pin; mod update refreshes it to HEAD. An explicit full 40- or 64-hex-character commit remains an exact constraint.
SemVer requirements select the maximum requested minimum. SemVer and SHA requirements are compatible only when the selected tag points to that exact commit. Different explicit commits or a selected tag at another commit conflict; SHA values, dates, and commit ancestry are not given a semantic version order. For a nested module in proto/user, version v1.2.3 uses tag proto/user/v1.2.3. Each module has its own lock entry and roots.
A local replace may target a nested module directory. Its native manifest must declare the replaced identity, and its requirements participate in the effective graph. Relative paths always use the main manifest directory, even at transitive depths; absolute paths are used directly. Historical breaking comparisons map in-repository replacements to the corresponding revision snapshot and reject external local paths. Preserving the lock is an explicit EasyP invariant, not a claim that Go never changes go.sum.
For example, with repo/foo/protobuf.mod containing roots proto, EasyP reads files under the physical repository path repo/foo/proto. A file at repo/foo/proto/user/v1/user.proto has the protobuf import path user/v1/user.proto: import paths are relative to the resolved root, so the module directory and the root directory are not repeated in imports. With roots ., the physical root is repo/foo.
Major version identities
v0 and v1 use the same unsuffixed module path. v2 and later require a final /vN component matching the SemVer major, with no leading zeros: require github.com/acme/weather/v2 v2.1.0. /v0, /v1, /v01 and /v2.0 are invalid module suffixes. Ordinary components such as /2024 and /v2beta are not suffixes. This does not restrict package directories or protobuf import paths. Go's special gopkg.in/name.vN spelling is recognized by the same suffix helpers.
The rule applies to declared module identities, requirements, replacement source identities, fetched native metadata and lock entries. Full commits and omitted versions still require the exact requested native identity. Absolute local Git paths and explicit URLs are supported; the logical URL host/path is checked separately from transport credentials and ports. EasyP preserves the original identity spelling.
| Identity | Physical directory containing protobuf.mod | Tag for the example release |
|---|---|---|
repo | repository root | v1.2.0 |
repo/v2 | root or v2/ | v2.0.0 |
repo/sub/v2 | sub/ or sub/v2/ | sub/v2.0.0 |
The major suffix is logical and is not included in the tag prefix: v2/v2.0.0 is not the release tag for repo/v2. Both lightweight and annotated tags work. The manifest at an allowed location must declare the exact requested identity; finding a tag alone is insufficient.
repo and repo/v2 can coexist as distinct module, lock and replacement identities. MVS chooses the highest requested minimum per identity. Major-version identities do not rename protobuf packages or disambiguate import paths; the author must provide distinct paths, and duplicates still fail. Checked mod tidy can repair consumer import declarations after a verified dependency namespace change; see root changes during updates. Same-major updates, exact SHA/tag agreement, immutable tags, local replacement lock preservation and frozen verification continue to apply.
The pre-module +incompatible exception is supported only for unsuffixed v2+ revisions without a native protobuf.mod. EasyP reads the underlying tag without the suffix and verifies metadata on the exact fetched or cached commit before accepting the lock entry. It rejects native manifests even when the marker is present. Legacy updates retain the marker; local replacements remain unversioned overlays and never publish their graph to the lock. Migration never silently renames a source or changes its version.
See Go major version suffixes and mapping versions to commits.
As in Go, an unversioned local replacement may contain a native manifest with the same unsuffixed identity while replacing an explicit legacy +incompatible requirement. This does not certify the published revision: the overlay preserves the shared lock, and frozen mode rejects replacements. Published fetches and both cold and warm locked installations still enforce the pre-native metadata check.
MCP reference
easyp_config_describe describes this format without reading local files. Use file: protobuf.mod and path: require[].version. See configuration reference via MCP.