With Go modules, is that possible to reference a package which hasn't gotten a module support

128 views
Skip to first unread message

Roman Gomoliako

unread,
Jul 9, 2019, 9:21:48 AM7/9/19
to golang-nuts
For a project considering switching to Go modules, is that possible to reference a package without support of modules (doesn't have a go.mod/go.sum files)?

module anEnterpriseCompany.com/aProject

require anEnterpriseCompany.com/anotherProject v0.0.0

go
1.12

"anEnterpriseCompany.com/anotherProject" can't be modified to support Go modules for some internal reasons. Is there some ways to resolve this?

Thanks,

Roman

t hepudds

unread,
Jul 9, 2019, 3:08:52 PM7/9/19
to golang-nuts

Hi Roman,

> For a project considering switching to Go modules, is that possible to 
> reference a package without support of modules (doesn't have a go.mod/go.sum files)?

Yes, as far I understand, that should usually work.

Using your example of wanting to consume a non-module dependency anEnterpriseCompany.com/anotherProject, a module-based consumer should be able to do things like:

  $ go get anEnterpriseCompany.com/anotherProject@<tag>
  $ go get anEnterpriseCompany.com/anotherProject@<hash>
  $ go get anEnterpriseCompany.com/anotherProject@latest

There is a longer discussion in this FAQ on the Modules wiki:


Hope that helps,
thepudds

Roman Gomoliako

unread,
Jul 10, 2019, 5:00:48 AM7/10/19
to golang-nuts
thepudds,

Thank you for the reply, thanks for the link!

The follow-up question, what if the project isn't hosted anywhere yet? Like, I have a module-opted package and it tries to use a local module-unaware package. For a local module-aware package usage one would use `replace` declaration. But I found it doesn't work for module-unaware packages. Having the module-unaware anEnterpriseCompany.com/anotherProject only locally I can't ahieve a successfull compilation using `replace`:

module anEnterpriseCompany.com/aProject

require anEnterpriseCompany.com/anotherProject v0.0.0

replace anEnterpriseCompany.com/anotherProject => ../some/where/up/on/a/filesystem/anotherProject

go 
1.12

Tamás Gulácsi

unread,
Jul 10, 2019, 11:21:57 AM7/10/19
to golang-nuts
If it's on your local filesystem, you can easily add a go.mod file to it...
Reply all
Reply to author
Forward
0 new messages