Go generate only scans main.go : <p>I am having some trouble using go generate to generate a grpc server when running go generate from the root of my project directory.</p>

<p>When I run <code>go generate -v</code> it only returns <code>main.go</code>. However, the directives are defined in one the subpackages. If I run <code>go generate</code> in the sub package it works as expected. I expected the imports to ensure that <code>go generate</code> would find the subpackages and run the directives.</p>

<p>The project has the following structure:</p>

<pre><code>cmd/
  root.go
  run.go
pkg/
  subpkg/
    protobuf/
      proto1.proto
    subpkg.go
main.go
</code></pre>

<p>Contents of subpkg.go</p>

<pre><code>//go:generate protoc -I ./protobuf --go_out=plugins=grpc:./protobuf ./protobuf/proto1.proto
package subpkg

</code></pre>

<p>Contents of main.go:</p>

<pre class="lang-golang prettyprint-override"><code>package main

import (
    "fmt"
    "os"

    "my-project/cmd"
)

func main() {
    if err := cmd.RootCommand.Execute(); err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
}

</code></pre>

<p>In the run.go package, I import the package subpkg.</p>

<p>How do I ensure go generate can be run from the root of the project and execute all directives in all sub packages.</p>
