-1

Let's say I am working on a Go project, called X, which has a dependency upon a repo Y. I am not using go mods in my project X yet.

I have now added Y as a git submodule in my project X in the vendor pkg using the following command: git submodule add <URL to Git repo> <Directory in vendor pkg>.

The repo Y has sub-dependencies on a project, say Z defined inside it in Gopkg.toml and go.mod files. Now, when I put my code to a server and run the following command to fetch the submodule Y, files of dependency Z are still missing.

What should I do to download the files for Z using the Gopkg.toml and go.mod files without explicitly going into Y and downloading.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Rajvir
  • 108
  • 7
  • "without explicitly going into Y and downloading"; is there a reason you don't want to do this? – Alex Feb 02 '21 at 05:17
  • @Alex yes, so while I deploy using Jenkins job, I dont have to use brute-force to make it work. I should be able to execute commands at the root level of project X. – Rajvir Feb 02 '21 at 06:35
  • 1
    "I am not using go mods in my project X yet." Then you are doing it **wrong** and there is no way to help you. Use Go modules now, everywhere. – Volker Feb 02 '21 at 06:56
  • @Volker I have modified a vendor pkg, hence unable to shift to go mod. – Rajvir Feb 02 '21 at 07:41
  • 2
    "I have modified a vendor pkg" So you forked a dependency. Then just import that forked dependency. Or `replace` that dependency with your fork. This is a XY problem. You either can do it the hard way and work against the tooling or do it the easy way and work with the tooling. – Volker Feb 02 '21 at 08:25
  • @Volker Agreed. I was think XY problem as well when I read that comment, hence my answer below. – VonC Feb 02 '21 at 08:27
  • 2
    Use Go modules. They support everything you're trying to do, and it does so cleanly. Using unsupported tools, as you are attempting, leads to a mess, as you are experiencing. – Jonathan Hall Feb 02 '21 at 08:49
  • I had to use pre-module Go with a dependency manager for a while. Using the modules is *much* better. – torek Feb 02 '21 at 10:05
  • Got it @Flimzy, thanks for the heads up. – Rajvir Feb 02 '21 at 10:41
  • @Rajvir You provided the relevant information in a comment and your question is a typical XY question so I see no problem with a downvote. Also: There is no need I add a second answer, I just upvoted VonC's. – Volker Feb 02 '21 at 11:01

1 Answers1

3

"I have modified a vendor pkg, hence unable to shift to go mod"

Actually, you can reference Y in your go.mod, using a replace directive.

replace example.com/original/import/path => vendor/Y

That way, a go mod tidy/go mod download should download Z.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250