Resolving Protoc Artifact From Maven Central Repo

Overview

Starting with versions 2.6.1 and 3.0.0-alpha-2 of protoc, its binary executables for all major operating systems are available as artifacts in Maven central. These artifacts can be referenced in plugin configuration as described below. The plugin automatically resolves and downloads the protoc executable, and uses it for compiling protobuf definitions.

Usage

It is recommended to use os-maven-plugin to automatically generate a classifier for the current OS and architecture. The same plugin is used by protobuf team at Google to generate classifiers for protoc artifacts.

Plugin parameter protocArtifact can be used for specifying artifact coordinates in a groupId:artifactId:version[:type[:classifier]] format.

A sample configuration is provided below:

<project>
  ...
  <build>
    <extensions>
      <extension>
        <groupId>kr.motd.maven</groupId>
        <artifactId>os-maven-plugin</artifactId>
        <version>1.6.0</version>
      </extension>
    </extensions>
    <plugins>
      <plugin>
        <groupId>org.xolstice.maven.plugins</groupId>
        <artifactId>protobuf-maven-plugin</artifactId>
        <version>0.6.1</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>test-compile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <protocArtifact>com.google.protobuf:protoc:3.4.0:exe:${os.detected.classifier}</protocArtifact>
        </configuration>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

Eclipse users, please also read the following notes.