Skip to content

Commit 45cb069

Browse files
author
Jay Conrod
committed
_content/doc: clarify that a replace directive does not imply require
This came up a couple times in Slack recently. I was confused about this myself before we switched to -mod=readonly. Change-Id: I3bafe347f4f9ecc3599e4b2568701422c95066c3 Reviewed-on: https://go-review.googlesource.com/c/website/+/322669 Trust: Jay Conrod <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 64052e7 commit 45cb069

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

_content/doc/modules/gomod-ref.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,20 @@ The `replace` directive can be useful in situations such as the following:
334334
* You've identified an issue with a dependency, have cloned the dependency's
335335
repository, and you're testing a fix with the local repository.
336336
337+
Note that a `replace` directive alone does not does not add a module to the
338+
[module graph](/ref/mod#glos-module-graph). A [`require` directive](#require)
339+
that refers to a replaced module version is also needed, either in the main
340+
module's `go.mod` file or a dependency's `go.mod` file. If you don't have a
341+
specific version to replace, you can use a fake version, as in the example
342+
below. Note that this will break modules that depend on your module, since
343+
`replace` directives are only applied in the main module.
344+
345+
```
346+
require example.com/mod v0.0.0-replace
347+
348+
replace example.com/mod v0.0.0-replace => ./mod
349+
```
350+
337351
For more on replacing a required module, including using Go tools to make the
338352
change, see:
339353

_content/ref/mod.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,12 @@ must match the module path it replaces.
675675
and are ignored in other modules. See [Minimal version
676676
selection](#minimal-version-selection) for details.
677677

678+
Note that a `replace` directive alone does not add a module to the [module
679+
graph](#glos-module-graph). A [`require` directive](#go-mod-file-require) that
680+
refers to a replaced module version is also needed, either in the main module's
681+
`go.mod` file or a dependency's `go.mod` file. A `replace` directive has no
682+
effect if the module version on the left side is not required.
683+
678684
```
679685
ReplaceDirective = "replace" ( ReplaceSpec | "(" newline { ReplaceSpec } ")" newline ) .
680686
ReplaceSpec = ModulePath [ Version ] "=>" FilePath newline

0 commit comments

Comments
 (0)