6

Suppose I have a monorepo and there are several individual golang services:

root    
└── services
        ├── svc1
        │   ├── go.mod
        │   ├── go.sum
        │   └── main.go
        └── svc2
            ├── go.mod
            ├── go.sum
            └── main.go

Whereas svc2 will depend on svc1 in the future. Also, it is a requirement that svc1 and svc2 can be released individually.

Is there a way I can publish the module indivdually? The go mod documentation only assume that there is only repo so it doesn't provide such flexibility.

2
  • 2
    The semantic version of the module is determined by repository tags, so I don't think you will be able to version each module separately in the same repository (at least on git). Apr 23, 2021 at 6:16
  • You may find this section of the go wiki helpful github.com/golang/go/wiki/… Apr 23, 2021 at 18:17

1 Answer 1

13

To tag a release version for a module within a subdirectory of a repository, add the subdirectory as a prefix of the tag, like svc1/v0.1.0.

Per https://golang.org/ref/mod#vcs-version:

If a module is defined in a subdirectory within the repository …, then each tag name must be prefixed with the module subdirectory, followed by a slash. For example, the module golang.org/x/tools/gopls is defined in the gopls subdirectory of the repository with root path golang.org/x/tools. The version v0.4.0 of that module must have the tag named gopls/v0.4.0 in that repository.

1
  • 1
    I was searching for this for hours and almost gave up thinking this might not be possible. Not sure why Google doesn't rank it from search higher.
    – Iblisto
    Jul 24, 2021 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.