protobuf:compile-custom

Full name:

org.xolstice.maven.plugins:protobuf-maven-plugin:0.6.1:compile-custom

Description:

This mojo executes the protoc compiler with the specified plugin executable to generate main sources from protocol buffer definitions. It also searches dependency artifacts for .proto files and includes them in the proto_path so that they can be referenced. Finally, it adds the .proto files to the project as resources so that they are included in the final artifact.

Attributes:

  • Requires a Maven project to be executed.
  • Requires dependency resolution of artifacts in scope: compile.
  • Since version: 0.4.1.
  • Binds by default to the lifecycle phase: generate-sources.

Required Parameters

Name Type Since Description
<attachDescriptorSet> boolean 0.4.1 If set to true, the generated descriptor set will be attached to the build.
Default value is: false.
<attachProtoSources> boolean 0.4.1 If set to true, then the specified protobuf source files from this project will be attached as resources to the build, for subsequent inclusion into the final artifact. This is the default behaviour, as it allows downstream projects to import protobuf definitions from the upstream projects, and those imports are automatically resolved at build time.

If distribution of .proto source files is undesirable for security reasons or because of other considerations, then this parameter should be set to false.


Default value is: true.
<descriptorSetFileName> String 0.3.0 The descriptor set file name. Only used if writeDescriptorSet is set to true.
Default value is: ${project.build.finalName}.protobin.
<descriptorSetOutputDirectory> File 0.3.0 This is the directory into which the (optional) descriptor set file will be created.
Default value is: ${project.build.directory}/generated-resources/protobuf/descriptor-sets.
<hashDependentPaths> boolean 0.4.1 Set this to false to disable hashing of dependent jar paths. This plugin expands jars on the classpath looking for embedded .proto files. Normally these paths are hashed (MD5) to avoid issues with long file names on windows. However if this property is set to false longer paths will be used.
Default value is: true.
<pluginId> String 0.4.1 A unique id that identifies the plugin to protoc. Cannot be one of the built-in protoc plugins:
  • java
  • javanano
  • js
  • csharp
  • cpp
  • python
  • descriptor-set

User property is: protocPluginId.
<protoSourceRoot> File 0.4.1 The source directories containing the .proto definitions to be compiled.
Default value is: ${basedir}/src/main/proto.
<temporaryProtoFileDirectory> File 0.4.1 Since protoc cannot access jars, proto files in dependencies are extracted to this location and deleted on exit. This directory is always cleaned during execution.
Default value is: ${project.build.directory}/protoc-dependencies.
<writeDescriptorSet> boolean 0.3.0 If set to true, the compiler will generate a binary descriptor set file for the specified .proto files.
Default value is: false.

Optional Parameters

Name Type Since Description
<additionalProtoPathElements> File[] 0.4.1 Additional source paths for .proto definitions.
<checkStaleness> boolean 0.4.1 Normally protoc is invoked on every execution of the plugin. Setting this parameter to true will enable checking timestamps of source protobuf definitions vs. generated sources.
Default value is: false.
<clearOutputDirectory> boolean 0.4.0 When true, the output directory will be cleared out prior to code generation. With the latest versions of protoc (2.5.0 or later) this is generally not required, although some earlier versions reportedly had issues with running two code generations in a row without clearing out the output directory in between.
Default value is: true.
<descriptorSetClassifier> String 0.4.1 If generated descriptor set is to be attached to the build, specifies an optional classifier.
<excludes> String[] 0.4.1 A list of <exclude> elements specifying the protobuf definition files (by pattern) that should be excluded from compilation. When not specified, the default excludes will be empty:
<excludes>
</excludes>

<forceMojoExecution> boolean 0.2.0 Usually most of protobuf mojos will not get executed on parent poms (i.e. projects with packaging type 'pom'). Setting this parameter to true will force the execution of this mojo, even if it would usually get skipped in this case.
Default value is: false.
User property is: protoc.force.
<includeDependenciesInDescriptorSet> boolean 0.3.0 If true and writeDescriptorSet has been set, the compiler will include all dependencies in the descriptor set making it "self-contained".
Default value is: false.
<includeSourceInfoInDescriptorSet> boolean 0.4.4 If true and writeDescriptorSet has been set, do not strip SourceCodeInfo from the FileDescriptorProto. This results in vastly larger descriptors that include information about the original location of each decl in the source file as well as surrounding comments.
Default value is: false.
<includes> String[] 0.4.1 A list of <include> elements specifying the protobuf definition files (by pattern) that should be included in compilation. When not specified, the default includes will be:
<includes>
 <include>**/*.proto</include>
</includes>

<outputDirectory> File 0.4.1 This is the directory where the generated code will be placed. If this parameter is unspecified, then the default location is constructed as follows:
${project.build.directory}/generated-sources/protobuf/<pluginId>
User property is: protocPluginOutputDirectory.
<pluginArtifact> String 0.4.1 Plugin artifact specification, in groupId:artifactId:version[:type[:classifier]] format. When this parameter is set, the specified artifact will be resolved as a plugin executable.
User property is: protocPluginArtifact.
<pluginExecutable> String 0.4.1 An optional path to plugin executable. If unspecified, alternative options must be used (e.g. toolchains).
User property is: protocPluginExecutable.
<pluginParameter> String 0.4.1 An optional parameter to be passed to the plugin. Cannot contain colon (:) symbols.
User property is: protocPluginParameter.
<pluginTool> String 0.4.1 If pluginToolchain is specified, this parameter specifies the tool in the toolchain, which is to be resolved as plugin executable.
User property is: protocPluginTool.
<pluginToolchain> String 0.4.1 A name of an optional custom toolchain that can be used to locate the plugin executable. The toolchain must be registered as a build extension and initialised properly.
User property is: protocPluginToolchain.
<protocArtifact> String 0.4.1 Protobuf compiler artifact specification, in groupId:artifactId:version[:type[:classifier]] format. When this parameter is set, the plugin attempts to resolve the specified artifact as protoc executable.
User property is: protocArtifact.
<protocExecutable> String 0.4.1 This is the path to the protoc executable. When this parameter is not set, the plugin attempts to load a protobuf toolchain and use it locate protoc executable. If no protobuf toolchain is defined in the project, the protoc executable in the PATH is used.
User property is: protocExecutable.
<protocPluginDirectory> File 0.3.0 A directory where native launchers for java protoc plugins will be generated.
Default value is: ${project.build.directory}/protoc-plugins.
<protocPlugins> List 0.4.1 Specifies one of more custom protoc plugins, written in Java and available as Maven artifacts. An executable plugin will be created at execution time. On UNIX the executable is a shell script and on Windows it is a WinRun4J .exe and .ini.
<skip> boolean 0.2.0 When true, skip the execution.
Default value is: false.
User property is: protoc.skip.
<staleMillis> long 0.4.1 Sets the granularity in milliseconds of the last modification date for testing whether source protobuf definitions need recompilation.

This parameter is only used when checkStaleness parameter is set to true.

If the project is built on NFS it's recommended to set this parameter to 10000.


Default value is: 0.
<useArgumentFile> boolean 0.6.0 If set to true, all command line arguments to protoc will be written to a file, and only a path to that file will be passed to protoc on the command line. This helps prevent Command line is too long errors when the number of .proto files is large.

NOTE: This is only supported for protoc 3.5.0 and higher.


Default value is: false.

Parameter Details

<additionalProtoPathElements>

Additional source paths for .proto definitions.
  • Type: java.io.File[]
  • Since: 0.4.1
  • Required: No

<attachDescriptorSet>

If set to true, the generated descriptor set will be attached to the build.
  • Type: boolean
  • Since: 0.4.1
  • Required: Yes
  • Default: false

<attachProtoSources>

If set to true, then the specified protobuf source files from this project will be attached as resources to the build, for subsequent inclusion into the final artifact. This is the default behaviour, as it allows downstream projects to import protobuf definitions from the upstream projects, and those imports are automatically resolved at build time.

If distribution of .proto source files is undesirable for security reasons or because of other considerations, then this parameter should be set to false.

  • Type: boolean
  • Since: 0.4.1
  • Required: Yes
  • Default: true

<checkStaleness>

Normally protoc is invoked on every execution of the plugin. Setting this parameter to true will enable checking timestamps of source protobuf definitions vs. generated sources.
  • Type: boolean
  • Since: 0.4.1
  • Required: No
  • Default: false

<clearOutputDirectory>

When true, the output directory will be cleared out prior to code generation. With the latest versions of protoc (2.5.0 or later) this is generally not required, although some earlier versions reportedly had issues with running two code generations in a row without clearing out the output directory in between.
  • Type: boolean
  • Since: 0.4.0
  • Required: No
  • Default: true

<descriptorSetClassifier>

If generated descriptor set is to be attached to the build, specifies an optional classifier.
  • Type: java.lang.String
  • Since: 0.4.1
  • Required: No

<descriptorSetFileName>

The descriptor set file name. Only used if writeDescriptorSet is set to true.
  • Type: java.lang.String
  • Since: 0.3.0
  • Required: Yes
  • Default: ${project.build.finalName}.protobin

<descriptorSetOutputDirectory>

This is the directory into which the (optional) descriptor set file will be created.
  • Type: java.io.File
  • Since: 0.3.0
  • Required: Yes
  • Default: ${project.build.directory}/generated-resources/protobuf/descriptor-sets

<excludes>

A list of <exclude> elements specifying the protobuf definition files (by pattern) that should be excluded from compilation. When not specified, the default excludes will be empty:
<excludes>
</excludes>
  • Type: java.lang.String[]
  • Since: 0.4.1
  • Required: No

<forceMojoExecution>

Usually most of protobuf mojos will not get executed on parent poms (i.e. projects with packaging type 'pom'). Setting this parameter to true will force the execution of this mojo, even if it would usually get skipped in this case.
  • Type: boolean
  • Since: 0.2.0
  • Required: No
  • User Property: protoc.force
  • Default: false

<hashDependentPaths>

Set this to false to disable hashing of dependent jar paths. This plugin expands jars on the classpath looking for embedded .proto files. Normally these paths are hashed (MD5) to avoid issues with long file names on windows. However if this property is set to false longer paths will be used.
  • Type: boolean
  • Since: 0.4.1
  • Required: Yes
  • Default: true

<includeDependenciesInDescriptorSet>

If true and writeDescriptorSet has been set, the compiler will include all dependencies in the descriptor set making it "self-contained".
  • Type: boolean
  • Since: 0.3.0
  • Required: No
  • Default: false

<includeSourceInfoInDescriptorSet>

If true and writeDescriptorSet has been set, do not strip SourceCodeInfo from the FileDescriptorProto. This results in vastly larger descriptors that include information about the original location of each decl in the source file as well as surrounding comments.
  • Type: boolean
  • Since: 0.4.4
  • Required: No
  • Default: false

<includes>

A list of <include> elements specifying the protobuf definition files (by pattern) that should be included in compilation. When not specified, the default includes will be:
<includes>
 <include>**/*.proto</include>
</includes>
  • Type: java.lang.String[]
  • Since: 0.4.1
  • Required: No

<outputDirectory>

This is the directory where the generated code will be placed. If this parameter is unspecified, then the default location is constructed as follows:
${project.build.directory}/generated-sources/protobuf/<pluginId>
  • Type: java.io.File
  • Since: 0.4.1
  • Required: No
  • User Property: protocPluginOutputDirectory

<pluginArtifact>

Plugin artifact specification, in groupId:artifactId:version[:type[:classifier]] format. When this parameter is set, the specified artifact will be resolved as a plugin executable.
  • Type: java.lang.String
  • Since: 0.4.1
  • Required: No
  • User Property: protocPluginArtifact

<pluginExecutable>

An optional path to plugin executable. If unspecified, alternative options must be used (e.g. toolchains).
  • Type: java.lang.String
  • Since: 0.4.1
  • Required: No
  • User Property: protocPluginExecutable

<pluginId>

A unique id that identifies the plugin to protoc. Cannot be one of the built-in protoc plugins:
  • java
  • javanano
  • js
  • csharp
  • cpp
  • python
  • descriptor-set
  • Type: java.lang.String
  • Since: 0.4.1
  • Required: Yes
  • User Property: protocPluginId

<pluginParameter>

An optional parameter to be passed to the plugin. Cannot contain colon (:) symbols.
  • Type: java.lang.String
  • Since: 0.4.1
  • Required: No
  • User Property: protocPluginParameter

<pluginTool>

If pluginToolchain is specified, this parameter specifies the tool in the toolchain, which is to be resolved as plugin executable.
  • Type: java.lang.String
  • Since: 0.4.1
  • Required: No
  • User Property: protocPluginTool

<pluginToolchain>

A name of an optional custom toolchain that can be used to locate the plugin executable. The toolchain must be registered as a build extension and initialised properly.
  • Type: java.lang.String
  • Since: 0.4.1
  • Required: No
  • User Property: protocPluginToolchain

<protoSourceRoot>

The source directories containing the .proto definitions to be compiled.
  • Type: java.io.File
  • Since: 0.4.1
  • Required: Yes
  • Default: ${basedir}/src/main/proto

<protocArtifact>

Protobuf compiler artifact specification, in groupId:artifactId:version[:type[:classifier]] format. When this parameter is set, the plugin attempts to resolve the specified artifact as protoc executable.
  • Type: java.lang.String
  • Since: 0.4.1
  • Required: No
  • User Property: protocArtifact

<protocExecutable>

This is the path to the protoc executable. When this parameter is not set, the plugin attempts to load a protobuf toolchain and use it locate protoc executable. If no protobuf toolchain is defined in the project, the protoc executable in the PATH is used.
  • Type: java.lang.String
  • Since: 0.4.1
  • Required: No
  • User Property: protocExecutable

<protocPluginDirectory>

A directory where native launchers for java protoc plugins will be generated.
  • Type: java.io.File
  • Since: 0.3.0
  • Required: No
  • Default: ${project.build.directory}/protoc-plugins

<protocPlugins>

Specifies one of more custom protoc plugins, written in Java and available as Maven artifacts. An executable plugin will be created at execution time. On UNIX the executable is a shell script and on Windows it is a WinRun4J .exe and .ini.
  • Type: java.util.List
  • Since: 0.4.1
  • Required: No

<skip>

When true, skip the execution.
  • Type: boolean
  • Since: 0.2.0
  • Required: No
  • User Property: protoc.skip
  • Default: false

<staleMillis>

Sets the granularity in milliseconds of the last modification date for testing whether source protobuf definitions need recompilation.

This parameter is only used when checkStaleness parameter is set to true.

If the project is built on NFS it's recommended to set this parameter to 10000.

  • Type: long
  • Since: 0.4.1
  • Required: No
  • Default: 0

<temporaryProtoFileDirectory>

Since protoc cannot access jars, proto files in dependencies are extracted to this location and deleted on exit. This directory is always cleaned during execution.
  • Type: java.io.File
  • Since: 0.4.1
  • Required: Yes
  • Default: ${project.build.directory}/protoc-dependencies

<useArgumentFile>

If set to true, all command line arguments to protoc will be written to a file, and only a path to that file will be passed to protoc on the command line. This helps prevent Command line is too long errors when the number of .proto files is large.

NOTE: This is only supported for protoc 3.5.0 and higher.

  • Type: boolean
  • Since: 0.6.0
  • Required: No
  • Default: false

<writeDescriptorSet>

If set to true, the compiler will generate a binary descriptor set file for the specified .proto files.
  • Type: boolean
  • Since: 0.3.0
  • Required: Yes
  • Default: false