Import Existing Go Application into the Bazel Monorepo

load("@bazel_gazelle//:def.bzl", "gazelle")# gazelle:prefix github.com/hardyantz/go-hello-worldgazelle(name = "gazelle")load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")go_binary(
name = "hello-world",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
$ bazel run //:gazelle --update-repos -from_file=go.mod

You can run the same command in the future to update existing WORKSPACE file in root folder to include new go library from you go.mod

$ bazel run //:gazelle
$ bazel run //packages/go-existing:hello-world
$ bazel build //packages/go-existing:hello-world
bazel-bin/packages/go-existing/darwin_amd64_stripped/hello-world
$ ./bazel-bin/packages/go-existing/darwin_amd64_stripped/hello-world

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store