Skip to content

Instantly share code, notes, and snippets.

@ngerakines
Created October 18, 2012 15:43
Show Gist options
  • Save ngerakines/3912658 to your computer and use it in GitHub Desktop.
Save ngerakines/3912658 to your computer and use it in GitHub Desktop.

About

The maven-protobuff project contains a lightweight maven plugin used to compile proto files.

Features

  • Will automatically extract .proto files out of dependency jars and put them into “//target/protos”.
  • Will compile your module/project proto files into the “//src/main/java” directory for checkin.
  • Works with both standard and multi-module projects.

Configuration

  • "clear" - true by default, will delete the temp //target/protos directory before running.
  • "verbose" - false by default, will output additional information, including the protoc command parameters.
  • "protoc" - "protoc" by default, the protoc executable to use. The default value assumes you have the protoc executable on your path.
  • "protoSources" / "protoSource" - A list of proto files in your project to be compiled.
  • "includePaths" / "includePath" - A list of paths to add to the protoc include path list. If not specified will default to "src/main/resources" and, if there were dependencies with proto files, "target/protos/" and "target/protos/protobuf".

Usage

To use it, simply execute the “proto:compile” target like so:

$ mvn maven-protobuff:compile

In the following usage example, the "protobuf-build" profile is used to selectively build proto files.

	<profiles>
		<profile>
			<id>protobuf-build</id>
			<build>
				<plugins>
					<plugin>
						<groupId>com.blizzard</groupId>
						<artifactId>maven-protobuff</artifactId>
						<version>1.0.3</version>
						<executions>
							<execution>
								<id>generate-sources</id>
								<phase>generate-sources</phase>
								<configuration>
									<verbose>true</verbose>
									<protoSources>
										<protoSource>src/main/resources/com/blizzard/nexus/nexus.proto</protoSource>
									</protoSources>
								</configuration>
								<goals>
									<goal>compile</goal>
								</goals>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>
	</profiles>

License

Copyright (c) 2012 Blizzard Entertainment

Open sourced under the MIT license. See the included LICENSE file for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment