title: Automatically generate Java from .proto with maven/m2e in Eclipse IDE
body: <p>For my team, I'd like to configure maven/eclipse build to automatically generate Java code from <code>*.proto</code> files (in a project that uses <a href="https://github.com/grpc/grpc-java" rel="noreferrer">gRPC</a>). Currently one needs to run <code>mvn generate-source</code> or <code>mvn protobuf:compile</code> (as in plugin <a href="https://www.xolstice.org/protobuf-maven-plugin/usage.html" rel="noreferrer">usage page</a>). Or what is the same add Run configuration to invoke maven goal <code>compile</code>.</p>
  
  <p>Whenever Eclipse Maven project is refreshed (<kbd>Alt</kbd>+<kbd>F5</kbd>) or IDE is restarted, project is rebuilt but without what should appear in <code>target/generated</code>, thus turning project into red. So one need to generate and refresh project (<kbd>F5</kbd>). UPDATE Eclipse has needed source folders configured in <code>.clathpath</code> file.</p>
  
  <p>As I know that should be m2e connector, but I could only find one <a href="https://github.com/masterzen/m2e-protoc-connector" rel="noreferrer">https://github.com/masterzen/m2e-protoc-connector</a> for the oldest Google<code>s plugin com.google.protobuf.tools:maven-protoc-plugin</code>, that is even not mentioned currently at <a href="https://github.com/grpc/grpc-java" rel="noreferrer">https://github.com/grpc/grpc-java</a></p>
  
  <p>We use exactly referenced/recommended</p>
  
  <pre><code>  &lt;groupId&gt;org.xolstice.maven.plugins&lt;/groupId&gt;
    &lt;artifactId&gt;protobuf-maven-plugin&lt;/artifactId&gt;
  </code></pre>
  
  <p>that is:</p>
  
  <pre><code>&lt;build&gt;
    &lt;extensions&gt;
      &lt;extension&gt;
        &lt;groupId&gt;kr.motd.maven&lt;/groupId&gt;
        &lt;artifactId&gt;os-maven-plugin&lt;/artifactId&gt;
        &lt;version&gt;1.4.1.Final&lt;/version&gt;
      &lt;/extension&gt;
    &lt;/extensions&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.xolstice.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;protobuf-maven-plugin&lt;/artifactId&gt;
        &lt;version&gt;0.5.0&lt;/version&gt;
        &lt;configuration&gt;
          &lt;protocArtifact&gt;com.google.protobuf:protoc:3.1.0:exe:${os.detected.classifier}&lt;/protocArtifact&gt;
          &lt;pluginId&gt;grpc-java&lt;/pluginId&gt;
          &lt;pluginArtifact&gt;io.grpc:protoc-gen-grpc-java:1.0.1:exe:${os.detected.classifier}&lt;/pluginArtifact&gt;
        &lt;/configuration&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;goals&gt;
              &lt;goal&gt;compile&lt;/goal&gt;
              &lt;goal&gt;compile-custom&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p>Related: </p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/4044891/linking-to-generated-java-protobuf-code-in-eclipse">Linking to generated Java protobuf code in Eclipse</a></li>
  <li>looked at this but that author was using other older, not supported now plugin  : <a href="https://stackoverflow.com/questions/23399188/eclipse-build-loop-caused-by-protobuf-generated-code-related-to-maven-project-b">Eclipse build loop caused by protobuf generated code (related to Maven Project Builder)</a><br>
  P.P.S That plugin <a href="https://github.com/igor-petruk/protobuf-maven-plugin" rel="noreferrer">https://github.com/igor-petruk/protobuf-maven-plugin</a> however has continuation as <a href="https://github.com/os72/protoc-jar-maven-plugin" rel="noreferrer">https://github.com/os72/protoc-jar-maven-plugin</a></li>
  </ul>