Giter Site home page Giter Site logo

os72 / protoc-jar-maven-plugin Goto Github PK

View Code? Open in Web Editor NEW
246.0 9.0 77.0 366 KB

Protocol Buffers protobuf maven plugin - based on protoc-jar multi-platform executable protoc JAR

Home Page: http://os72.github.io/protoc-jar-maven-plugin/

License: Apache License 2.0

Java 100.00%
java protobuf protocol-buffers protoc protobuf-compiler protoc-plugins maven-plugin

protoc-jar-maven-plugin's Introduction

protoc-jar-maven-plugin

Protocol Buffers protobuf maven plugin - performs protobuf code generation using protoc-jar multi-platform executable protoc JAR. Available on Maven Central: https://repo.maven.apache.org/maven2/com/github/os72/protoc-jar-maven-plugin/3.11.4/

Maven Central Join the chat at https://gitter.im/os72/community


Simple maven plugin to compile .proto files using protoc-jar embedded protoc compiler, providing some portability across the major platforms (Linux, Mac/OSX, and Windows). At build time the plugin detects the platform and executes the corresponding protoc binary.

Supports embedded protoc versions 2.4.1, 2.5.0, 2.6.1, 3.11.4, and any binaries (protoc and protoc plugins) available for download from maven central. Also supports pre-installed protoc binary

  • Support for FreeBSD on x86 platform (freebsd-x86_64), thanks kjopek
  • Support for Solaris on x86 platform (sunos-x86_64), thanks siepkes
  • Support for Linux on POWER8 platform (linux-ppcle_64), now from Google
  • Support for Linux on ARM platform (linux-aarch_64), now from Google
    • Older versions (2.4.1, 2.6.1, 3.4.0), thanks garciagorka

See also

Binaries

Usage

Documentation: see http://os72.github.io/protoc-jar-maven-plugin/, in particular run-mojo

Sample usage - compile in main cycle into target/generated-sources, add generated sources to project, use default protoc version and default src/main/protobuf source folder:

<plugin>
	<groupId>com.github.os72</groupId>
	<artifactId>protoc-jar-maven-plugin</artifactId>
	<version>3.11.4</version>
	<executions>
		<execution>
			<phase>generate-sources</phase>
			<goals>
				<goal>run</goal>
			</goals>
		</execution>
	</executions>
</plugin>

Sample usage - compile in main cycle into target/generated-sources, add generated sources to project, add all .proto sources to generated jar, include .proto files from direct maven dependencies, include additional imports:

<plugin>
	<groupId>com.github.os72</groupId>
	<artifactId>protoc-jar-maven-plugin</artifactId>
	<version>3.11.4</version>
	<executions>
		<execution>
			<phase>generate-sources</phase>
			<goals>
				<goal>run</goal>
			</goals>
			<configuration>
				<addProtoSources>all</addProtoSources>
				<includeMavenTypes>direct</includeMavenTypes>
				<includeDirectories>
					<include>src/main/more_proto_imports</include>
				</includeDirectories>
				<inputDirectories>
					<include>src/main/protobuf</include>
				</inputDirectories>
			</configuration>
		</execution>
	</executions>
</plugin>

Sample usage - download protoc and plugin binaries from maven repo, multiple output targets (example: gRPC):

<plugin>
	<groupId>com.github.os72</groupId>
	<artifactId>protoc-jar-maven-plugin</artifactId>
	<version>3.11.4</version>
	<executions>
		<execution>
			<phase>generate-sources</phase>
			<goals>
				<goal>run</goal>
			</goals>
			<configuration>
				<protocArtifact>com.google.protobuf:protoc:3.0.0</protocArtifact>
				<inputDirectories>
					<include>src/main/resources</include>
				</inputDirectories>
				<outputTargets>
					<outputTarget>
						<type>java</type>
					</outputTarget>
					<outputTarget>
						<type>grpc-java</type>
						<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.1</pluginArtifact>
					</outputTarget>
				</outputTargets>
			</configuration>
		</execution>
	</executions>
</plugin>

Sample usage - javalite, multiple output targets:

<plugin>
	<groupId>com.github.os72</groupId>
	<artifactId>protoc-jar-maven-plugin</artifactId>
	<version>3.11.4</version>
	<executions>
		<execution>
			<phase>generate-sources</phase>
			<goals>
				<goal>run</goal>
			</goals>
			<configuration>
				<inputDirectories>
					<include>src/main/resources</include>
				</inputDirectories>
				<outputTargets>
					<outputTarget>
						<type>java</type>
						<outputOptions>lite</outputOptions>
					</outputTarget>
					<outputTarget>
						<type>python</type>
						<outputOptions>lite</outputOptions>
					</outputTarget>
				</outputTargets>
			</configuration>
		</execution>
	</executions>
</plugin>

Sample usage - compile in test cycle, multiple output targets, don't alter project (<addSources>: none):

<plugin>
	<groupId>com.github.os72</groupId>
	<artifactId>protoc-jar-maven-plugin</artifactId>
	<version>3.11.4</version>
	<executions>
		<execution>
			<phase>generate-test-sources</phase>
			<goals>
				<goal>run</goal>
			</goals>
			<configuration>
				<protocVersion>2.4.1</protocVersion>
				<inputDirectories>
					<include>src/test/resources</include>
				</inputDirectories>
				<outputTargets>
					<outputTarget>
						<type>java</type>
						<addSources>none</addSources>
						<outputDirectory>src/test/java</outputDirectory>
					</outputTarget>
					<outputTarget>
						<type>descriptor</type>
						<addSources>none</addSources>
						<outputDirectory>src/test/resources</outputDirectory>
					</outputTarget>
				</outputTargets>
			</configuration>
		</execution>
	</executions>
</plugin>

Sample usage - generate java shaded for use with protobuf-java-shaded-241, don't alter project:

<plugin>
	<groupId>com.github.os72</groupId>
	<artifactId>protoc-jar-maven-plugin</artifactId>
	<version>3.11.4</version>
	<executions>
		<execution>
			<phase>generate-sources</phase>
			<goals>
				<goal>run</goal>
			</goals>
			<configuration>
				<protocVersion>2.4.1</protocVersion>
				<type>java-shaded</type>
				<addSources>none</addSources>
				<outputDirectory>src/main/java</outputDirectory>
				<inputDirectories>
					<include>src/main/protobuf</include>
				</inputDirectories>
			</configuration>
		</execution>
	</executions>
</plugin>

Credits

Originally based on

protoc-jar-maven-plugin's People

Contributors

arifogel avatar christrenkamp avatar davylandman avatar dependabot[bot] avatar harry-canva avatar ibauersachs avatar imedvedko avatar jvanbaa13 avatar os72 avatar pelletier avatar xanderatbackbonesystems avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

protoc-jar-maven-plugin's Issues

Not generating grpc service stubs

I have added maven configuration as follows.

      <plugin>
              <groupId>com.github.os72</groupId>
              <artifactId>protoc-jar-maven-plugin</artifactId>
              <version>3.5.1</version>
              <executions>
                  <execution>
                      <phase>generate-sources</phase>
                      <goals>
                          <goal>run</goal>
                      </goals>
                      <configuration>
                          <protocArtifact>com.google.protobuf:protoc:3.0.0</protocArtifact>
                          <inputDirectories>
                              <include>src/main/protobuf</include>
                          </inputDirectories>
                         <outputTargets>
                              <outputTarget>
                                  <type>java</type>
                                  <outputDirectory>src/main/java</outputDirectory>
                              </outputTarget>
                              <outputTarget>
                                  <type>grpc-java</type>
                                  <outputDirectory>src/main/java</outputDirectory>
                                  <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.1</pluginArtifact>
                              </outputTarget>
                          </outputTargets>
                      </configuration>
                  </execution>
              </executions>
       </plugin>

I am executing it by "mvn protoc-jar:run", however it skips the grpc service stubs, only coverts "messages" to java code.

output is

[INFO] Protoc version: 3.5.1
protoc-jar: protoc version: 3.5.1, detected platform: osx-x86_64 (mac os x/x86_64)
protoc-jar: embedded: bin/3.5.1/protoc-3.5.1-osx-x86_64.exe
protoc-jar: executing: [/var/folders/9y/w8qrc__9513dv57323sjdlmw0000gn/T/protocjar320569499467403052/bin/protoc.exe, --version]
libprotoc 3.5.1
[INFO] Protoc command: /var/folders/9y/w8qrc__9513dv57323sjdlmw0000gn/T/protocjar320569499467403052/bin/protoc.exe
[INFO] Input directories:
[INFO]     /Users/dev/learn/proto-java/src/main/protobuf
[INFO] Output targets:
[INFO]     java: /Users/dev/learn/proto-java/target/generated-sources (add: main, clean: false, plugin: null, outputOptions: null)
[INFO]     Processing (java): helloworld.proto
protoc-jar: executing: [/var/folders/9y/w8qrc__9513dv57323sjdlmw0000gn/T/protocjar320569499467403052/bin/protoc.exe, -I/Users/dev/learn/proto-java/src/main/protobuf, --java_out=/Users/dev/learn/proto-java/target/generated-sources, /Users/dev/learn/proto-java/src/main/protobuf/helloworld.proto]
[INFO] Adding generated classes to classpath

I've a simple proto file defined as

syntax = "proto3";
option java_multiple_files = true;
option java_package = "-.-.-.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";

package helloworld;

// The greeting service definition.
service Greeter {
    // Sends a greeting
    rpc SayHello (HelloRequest) returns (HelloReply) {}
    rpc SayHelloAgain (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
    string name = 1;
}

// The response message containing the greetings
message HelloReply {
    string message = 1;
}

I only output files generated as HelloReply, HelloReplyOrBuilder, HelloRequest, HelloRequestOrBuilder, HelloWorldProto. The Greeter Grpc service stub is missing.

Make protoc version 3.0 available through the plugin

As previously mentioned in #1, please consider publishing a version of the Maven plugin that will use your protoc-jar version 3.0.0(-a3), so that we'll have the "proto3" syntax available.

It looks like it may be as "simple" as creating a new branch and changing a few dependency versions in the POM, as well as updating the documentation to mention the new version. But then there's also the matter of releasing the artifact.

Thanks for providing this plugin. It's proven to be easy to use.

Where to put proto files?

I have proto files under /src/main/proto, but the below configuration did not work

<configuration>
                            <addProtoSources>all</addProtoSources>
                            <includeMavenTypes>direct</includeMavenTypes>
                            <includeDirectories>
                                <include>src/main/proto</include>
                            </includeDirectories>
</configuration>

Only if I create /src/main/protobuf directory and put files there, they are picked up. Any suggestions?

gRPC support

This is generic request.

Possibly will be solved by closing only #23

Make it easier to include "standard" types in the "google.protobuf" package

As of Protocol Buffers version 3, the compiler and runtime suite ship with several "standard" types in the google.protobuf package, such as Timestamp (in file google/protobuf/timestamp.proto) and Duration (in file google/protobuf/duration.proto). These files are not automatically available to the compiler, though.

The protoc Maven plugin accepts any number of includeDirectories elements to add directories to the compiler's include path. However, the files in question are packaged into Jar files, such as com.google.protobuf:protobuf-java:3.0.0-alpha-3.

Is there some way that I can point the protoc compiler at a file embedded in a Jar file? If not, would you consider unpacking these files from the Jar file (perhaps to a temporary directory, or to the "generated sources" directory tree) and making them available on the include path?

Restrict the plugin from cleaning generated sources

I have some pre-activities (generate sources by other means) which i am doing before the proto files are compiled. But it seems like the plugin always clears the generated sources folder before compiling the protos. Is there a way to restrict that?

Thanks
Ravi

Consider adding integration tests

Great work on this project! I love how it has embedded versions of protoc for different platforms and doesn't require on to be pre-installed.

I noticed the project doesn't have any integration tests. Having written some minor Maven plugins myself, I know this can be difficult, so I wanted to point out a new relatively new way to do it that's much easier than the old ways: http://takari.io/book/70-testing.html

Here are some examples:

Support binary artifact download

Support binary artifact download (maven artifact resolution) - for protoc binary, protoc plugins

Notation such as:

<protocArtifact>com.google.protobuf:protoc:3.1.0</protocArtifact>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.1</pluginArtifact>

Is it knows that outputTargets.outputTarget.addSources defaults to none?

See title. It took me a some time to discover that even though configuration.addSources defaults to "main", the one in outputTargets defaults to "none". Is this on purpose and if yes, would you mind documenting the outputTargets thing a little bit more thouroughly?

(otherwise, THANK YOU for the plugin, it overtook my previously favorite proto plugin)

Cannot execute protoc on /tmp with noexec

Hi,

I'm using Ubuntu 16.04, in my project I include protoc-jar-maven-plugin 3.2.0.1.

The maven build fails, complaining that it cannot execute protoc.exe. It seems that protoc thinks it is on windows.

A workaround is that I add
/usr/local/bin/protoc
in my pom.xml.

Thanks for checking this.

Sandor

Plugin does not work for several Directories with dependent Protos

Hello everyone,

I have two proto files in two different directories whereas one is dependent on the other and I don't get it to work, it seems to me that there might be a bug how imports are handled - either by the protoc compiler or the maven plugins (I have the same issue with the protobuf maven plugin. My directory structure looks approximately like this:

.
โ”œโ”€โ”€ pom.xml
โ”œโ”€โ”€ src
โ”‚ย ย  โ””โ”€โ”€ main
โ”‚ย ย      โ”œโ”€โ”€ java
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ ...
โ”‚ย ย      โ”œโ”€โ”€ proto
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ service.proto
โ”‚ย ย      โ””โ”€โ”€ resources
โ”‚ย ย          โ””โ”€โ”€ submodule
โ”‚ย ย              โ”œโ”€โ”€ protobuf
โ”‚ย ย              โ”‚ย ย  โ””โ”€โ”€ framework.proto

I need to preserve this directory structure and I also want to use the same framework.proto in other maven modules by accessing the resource path ideally.

The service.proto is using definitions of the framework by importing: import "framework.proto";

Now I tried to build the protobuf classes by copying the examples on the github site:

<plugin>
                <groupId>com.github.os72</groupId>
                <artifactId>protoc-jar-maven-plugin</artifactId>
                <version>3.5.1.1</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <addProtoSources>all</addProtoSources>
                            <includeStdTypes>true</includeStdTypes>
                            <includeDirectories>
                                <include>${basedir}/src/main/resources/submodule/protobuf</include>
                            </includeDirectories>
                            <inputDirectories>
                                <include>${basedir}/src/main/proto</include>
                            </inputDirectories>
                            <outputTargets>
                                <outputTarget>
                                    <type>java</type>
                                </outputTarget>
                                <outputTarget>
                                    <type>grpc-java</type>
                                    <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.1</pluginArtifact>
                                </outputTarget>
                            </outputTargets>
                        </configuration>
                    </execution>
                </executions>
</plugin>

Now the compilation is failing because the ServiceOuterClass : cannot find symbol [ERROR] symbol: variable Framework. Inspecting the generated sources on target/generated-sources, I realised that Framework.java was not generated, so I added the path to the <inputDirectories> - That will indeed generate the Java class, but the Java imports on the ServiceOuterClass will still be wrong unfortunatelly.

I have seen many issues on Stackoverflow and Github concerning the imports of other proto-files but unfortunatelly no good solution - any tipps are appreciated!

Make src/main/proto as default input

Make src/main/protobuf as default input

that make 3 lines not needed

                <inputDirectories>
                    <include>src/main/proto</include>
                </inputDirectories>

Than if <inputDirectories> is present it resets default to those specified.

How to include proto files from a jar?

Hi,

I am using a maven dependency in my project which contains some proto files. These proto files are being imported in my working project's .proto file. However, the imports do not work because it is only using proto files from src/main/resources. Now I cannot figure out how to include a jar as one of the input directories?

NullPointerException when includeStdTypes is set to true

Hi,

I just upgrade my project for protoc-3.5.1/protoc-jar-maven-plugin-3.5.1.1 to protoc-3.6.1/protoc-jar-maven-plugin-3.6.0.1 and I got this error during build:

  [ERROR] Failed to execute goal com.github.os72:protoc-jar-maven-plugin:3.6.0.1:run (default) on project deepblue-connect-domain: Execution default of goal com.github.os72:protoc-jar-maven-plugin:3.6.0.1:run failed. NullPointerException -> [Help 1]
  org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.os72:protoc-jar-maven-plugin:3.6.0.1:run (default) on project deepblue-connect-domain: Execution default of goal com.github.os72:protoc-jar-maven-plugin:3.6.0.1:run failed.
  		at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224)
  		at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
  		at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
  		at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
  		at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
  		at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
  		at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
  		at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
  		at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
  		at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
  		at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
  		at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
  		at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  		at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  		at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  		at java.lang.reflect.Method.invoke(Method.java:498)
  		at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
  		at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
  		at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
  		at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
  Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default of goal com.github.os72:protoc-jar-maven-plugin:3.6.0.1:run failed.
  		at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:143)
  		at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
  		... 19 more
  Caused by: java.lang.NullPointerException
  		at com.github.os72.protocjar.Protoc.extractStdTypes(Protoc.java:378)
  		at com.github.os72.protocjar.maven.ProtocJarMojo.performProtoCompilation(ProtocJarMojo.java:388)
  		at com.github.os72.protocjar.maven.ProtocJarMojo.execute(ProtocJarMojo.java:327)
  		at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
  		... 20 more

But when I comment <includeStdTypes>true</includeStdTypes> in my configuration, build finish with success!

My working configuration:

  <plugin>
  	<groupId>com.github.os72</groupId>
  	<artifactId>protoc-jar-maven-plugin</artifactId>
  	<version>${protoc-jar-maven-plugin.version}</version>
  	<executions>
  		<execution>
  			<phase>generate-sources</phase>
  			<goals>
  				<goal>run</goal>
  			</goals>
  			<configuration>
  				<protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:windows-x86_64</protocArtifact>
  				<!--<includeStdTypes>true</includeStdTypes>-->
  				<includeDirectories>
  					<include>${project.basedir}/build/include/</include>
  				</includeDirectories>
  				<inputDirectories>
  					<include>${mercurial.proto.sources.dir}/public/include/proto/</include>
  				</inputDirectories>
  				<outputDirectory>src/main/java</outputDirectory>
  			</configuration>
  		</execution>
  	</executions>
  </plugin>

Do you know this problem?

Allow generating source info when outputing descriptors

When outputing descriptors it's sometimes useful to have the SourceCodeInfo populated in the FileDescriptor. This is achieved by passing the --include_source_info argument to protoc, there's currently no way of doing this with the maven plugin.

protocArtifact and pluginArtifact pull artifacts that can't be executed on Mac OS

I'm using Maven 3.3.9. It looks like Maven dependencies get downloaded without the execute bit set, so the plugin fails when it tries to execute something pulled from Maven.

Unable to execute protoc-jar for my.proto: Cannot run program "/Users/nick/.m2/repository/com/google/protobuf/protoc/3.1.0/protoc-3.1.0-osx-x86_64.exe": error=13, Permission denied -> [Help 1]
Nicks-MacBook-Pro:3.1.0 nick$ pwd
/Users/nick/.m2/repository/com/google/protobuf/protoc/3.1.0
Nicks-MacBook-Pro:3.1.0 nick$ ls -l
total 9672
-rw-r--r--  1 nick  staff      170 Jan  9 10:19 _remote.repositories
-rw-r--r--  1 nick  staff  4943484 Jan  9 10:19 protoc-3.1.0-osx-x86_64.exe
-rw-r--r--  1 nick  staff       40 Jan  9 10:19 protoc-3.1.0-osx-x86_64.exe.sha1

/Users/nick/.m2/repository/io/grpc/protoc-gen-grpc-java/1.0.3/protoc-gen-grpc-java-1.0.3-osx-x86_64.exe: program not found or is not executable
--grpc-java_out: protoc-gen-grpc-java: Plugin failed with status code 1.
Nicks-MacBook-Pro:1.0.3 nick$ pwd
/Users/nick/.m2/repository/io/grpc/protoc-gen-grpc-java/1.0.3
Nicks-MacBook-Pro:1.0.3 nick$ ls -l
total 4216
-rw-r--r--  1 nick  staff      184 Jan  9 10:16 _remote.repositories
-rw-r--r--  1 nick  staff  2149556 Jan  9 10:16 protoc-gen-grpc-java-1.0.3-osx-x86_64.exe
-rw-r--r--  1 nick  staff       40 Jan  9 10:16 protoc-gen-grpc-java-1.0.3-osx-x86_64.exe.sha1

Fails to generate when proto file uses google/protobuf/empty.proto

When proto files use google/protobuf/empty.proto generation of source fails witth

google/protobuf/empty.proto: File not found.
ReleaseService.proto: Import "google/protobuf/empty.proto" was not found or had errors.
ReleaseService.proto:15:22: "google.protobuf.Empty" is not defined.

--grpc-java_out: protoc-gen-grpc-java: ???????????

While trying suggested in #20 (comment)

	<build>
		<plugins>
			<plugin>
				<groupId>com.github.os72</groupId>
				<artifactId>protoc-jar-maven-plugin</artifactId>
				<version>3.1.0.1</version>
				<executions>
					<execution>
						<phase>generate-sources</phase>
						<goals>
							<goal>run</goal>
						</goals>
						<configuration>
							<protocVersion>3.1.0</protocVersion>
							<inputDirectories>
								<include>src/main/proto</include>
							</inputDirectories>
							<outputTargets>
								<outputTarget>
									<type>java</type>
									<addSources>none</addSources>
									<outputDirectory>target/generated-sources/protobuf/java</outputDirectory>
								</outputTarget>
								<outputTarget>
									<type>descriptor</type>
									<addSources>none</addSources>
									<outputDirectory>target/generated-sources/protobuf/descriptor</outputDirectory>
								</outputTarget>
								<outputTarget>
									<type>grpc-java</type>
									<addSources>none</addSources>
									<cleanOutputFolder>false</cleanOutputFolder>
									<outputDirectory>target/generated-sources/protobuf/grpc-java</outputDirectory>
									<pluginPath>protoc-gen-grpc-java.exe</pluginPath>
								</outputTarget>
							</outputTargets>
						</configuration>
					</execution>
				</executions>
			</plugin>

I got

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporationใ€‚ไฟ็•™ๆ‰€ๆœ‰ๆƒๅˆฉใ€‚

D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin>mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building com.example.grpc.protoc-jar-maven-plugin 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ com.example.grpc.protoc-jar-maven-plugin ---
[INFO] Deleting D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\target
[INFO]
[INFO] --- protoc-jar-maven-plugin:3.1.0.1:run (default) @ com.example.grpc.protoc-jar-maven-plugin ---
[INFO] Protoc version: 3.1.0
protoc-jar: protoc version: 310, detected platform: windows 8.1/amd64
[INFO] Protoc command: C:\Users\Paul\AppData\Local\Temp\protocjar2106002337514533590\bin\protoc.exe
[INFO] Input directories:
[INFO]     D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\src\main\proto
[INFO] Output targets:
[INFO]     java: D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\target\generated-sources\protobuf\java (add: none, clean: false, plugin: null, outputOptions: null)
[INFO]     descriptor: D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\src\test\resources (add: none, clean: false, plugin: null, outputOptions: null)
[INFO]     grpc-java: D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\target\generated-sources\protobuf\grpc-java (add: none, clean: false, plugin: protoc-gen-grpc-java.exe, outputOptions: null)
[INFO] D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\target\generated-sources\protobuf\java does not exist. Creating...
[INFO] D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\target\generated-sources\protobuf\grpc-java does not exist. Creating...
[INFO]     Processing (java): helloworld.proto
protoc-jar: executing: [C:\Users\Paul\AppData\Local\Temp\protocjar2106002337514533590\bin\protoc.exe, -ID:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\src\main\proto, --java_out=D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\target\generated-sources\protobuf\java, D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\src\main\proto\helloworld.proto]
[INFO]     Processing (java): route_guide.proto
protoc-jar: executing: [C:\Users\Paul\AppData\Local\Temp\protocjar2106002337514533590\bin\protoc.exe, -ID:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\src\main\proto, --java_out=D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\target\generated-sources\protobuf\java, D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\src\main\proto\route_guide.proto]
[INFO]     Processing (descriptor): helloworld.proto
protoc-jar: executing: [C:\Users\Paul\AppData\Local\Temp\protocjar2106002337514533590\bin\protoc.exe, -ID:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\src\main\proto, --descriptor_set_out=D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\src\test\resources\helloworld.desc, --include_imports, D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\src\main\proto\helloworld.proto]
[INFO]     Processing (descriptor): route_guide.proto
protoc-jar: executing: [C:\Users\Paul\AppData\Local\Temp\protocjar2106002337514533590\bin\protoc.exe, -ID:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\src\main\proto, --descriptor_set_out=D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\src\test\resources\route_guide.desc, --include_imports, D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\src\main\proto\route_guide.proto]
[INFO]     Processing (grpc-java): helloworld.proto
protoc-jar: executing: [C:\Users\Paul\AppData\Local\Temp\protocjar2106002337514533590\bin\protoc.exe, -ID:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\src\main\proto, --grpc-java_out=D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\target\generated-sources\protobuf\grpc-java, --plugin=protoc-gen-grpc-java=protoc-gen-grpc-java.exe, D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\src\main\proto\helloworld.proto]
--grpc-java_out: protoc-gen-grpc-java: ???????????

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.840 s
[INFO] Finished at: 2016-11-11T22:21:46+08:00
[INFO] Final Memory: 9M/155M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.os72:protoc-jar-maven-plugin:3.1.0.1:run (default) on project com.example.grpc.protoc-jar-maven-plugin: protoc-jar failed for D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin\src\main\proto\helloworld.proto. Exit code 1 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

D:\Workspaces\workspace-sts-3.8.2.RELEASE\com.example.grpc.protoc-jar-maven-plugin>

outputDirectory not working for Java

Hello. This might be very simple, but I have been having trouble.

I am looking at different kinds of serializing and I would like to place all of the classes from the protobuf compiler into a folder within "generated-sources", lets say named "protobuf"

This is my current setup:

             <plugin>
                <groupId>com.github.os72</groupId>
                <artifactId>protoc-jar-maven-plugin</artifactId>
                <version>3.5.1.1</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <protocArtifact>com.google.protobuf:protoc:3.0.0</protocArtifact>
                            <inputDirectories>
                                <include>src/main/proto</include>
                            </inputDirectories>
                            <outputTargets>
                                <outputTarget>
                                    <type>java</type>
                                    <outputDirectory>${project.build.directory}/generated-sources/proto</outputDirectory>
                                </outputTarget>
                            </outputTargets>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

I have also tried to use the outputDirectorySuffix that was created but that didn't help at all

Thank You

How to exclude proto file in configuration?

For example

<configuration>
    <inputDirectories>
       <include>src/main/proto</include>
        <exclude>src/main/proto/openrtb.proto</exclude>
     </inputDirectories>
</configuration>

I want to exclude openrtb.proto file, as my proto files are extensions of openrtb.proto. I don't want to generate OpenRTB.java, then compile it to OpenRTB.class, the project has included OpenRTB.class through openrtb-core library.

have core dump file when use protoc in linux

[INFO] --- protoc-jar-maven-plugin:3.6.0.1:run (generate-sources) @ brpc-java ---
[INFO] Protoc version: 2.5.0
protoc-jar: protoc version: 2.5.0, detected platform: linux-x86_64 (linux/amd64)
protoc-jar: embedded: bin/2.5.0/protoc-2.5.0-linux-x86_64.exe
protoc-jar: executing: [/tmp/protocjar6053145344578931019/bin/protoc.exe, --version]
[INFO] Protoc command: /tmp/protocjar6053145344578931019/bin/protoc.exe
[INFO] Additional include types: /tmp/protocjar1509145097883442087/include

Is it possible to import protos using --proto_path?

Hey.
It seems to me that it's impossible for now to import other protos from different locations using --proto_path. If you can implement such feature, it would be nice. I suppose (according the code) that's it's not difficult.
PS: plugin is great:)

Have default <protocVersion>

as this plugin versioning follows protobuf versions, it can have defaults.
E.g. 3.1.0.1 -> 3.1.0

result together with #21 will be no need for <configuration> section at all in the simplest case.

Add website link to GitHub repo

The link to the Maven generated site is a bit buried in the long README. Adding it as the website for the repository would make it easier to find. (click the "Edit" link at the top near the repository description)

Fails behind proxy / download mechanism

Hi,

I cannot directly connect to maven central, but I use a mirror repository.
However, I cannot use it as the URL is hardcoded.

Also, you don't use maven mechanisms and http. The bug report for this is here: os72/protoc-jar#55

This issue is for to keep track of inclusion of the fix in the library into this plugin.

Only generating XXXOuterClass.java

I am trying to generate java source files from several proto files.

I am using Ubuntu 17.04.

I am using the following configurations:

<plugin>
    <groupId>com.github.os72</groupId>
    <artifactId>protoc-jar-maven-plugin</artifactId>
    <version>3.4.0.1</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
            	<includeStdTypes>true</includeStdTypes>
                <!-- <includeDirectories> <include>src/main/protobuf</include> </includeDirectories> -->
                <inputDirectories>
                    <include>src/main/proto/my-protos</include>
                </inputDirectories>
                <!-- Create java files. And put them in the src/main/java directory. -->
                <outputTargets>
                    <outputTarget>
                        <type>java</type>
                        <outputDirectory>src/main/java</outputDirectory>
                    </outputTarget>
                </outputTargets>
            </configuration>
        </execution>
    </executions>
</plugin>

However, only XXXOuterClass.java files are generated. There are no messages or services generated.

[Question] Is platform dependency taken care?

I believe Proto Buffers Compiler (protoc) is platform dependent. This plugin will download the appropriate protoc (according to the platform) and compile .proto files to .java files?

Is this plugin @threadSafe?

While doing a parallel build (see https://cwiki.apache.org/confluence/display/MAVEN/Parallel+builds+in+Maven+3), this warning pops up:

[WARNING] *****************************************************************
[WARNING] * Your build is requesting parallel execution, but project      *
[WARNING] * contains the following plugin(s) that have goals not marked   *
[WARNING] * as @threadSafe to support parallel building.                  *
[WARNING] * While this /may/ work fine, please look for plugin updates    *
[WARNING] * and/or request plugins be made thread-safe.                   *
[WARNING] * If reporting an issue, report it against the plugin in        *
[WARNING] * question, not against maven-core                              *
[WARNING] *****************************************************************
[WARNING] The following plugins are not marked @threadSafe in my-project:
[WARNING] com.github.os72:protoc-jar-maven-plugin:3.3.0.1
[WARNING] Enable debug to see more precisely which goals are not marked @threadSafe.
[WARNING] *****************************************************************

Is this plugin thread-safe? If yes, please mark it as such.

Cannot run program "protoc" because "no such file or directory"

Execute failed: java.io.IOException: Cannot run program "protoc" (in directory "/Users/zliu/git/my-repo/myModule1"): error=2, No such file or directory -> [Help 1]

Supposedly, with this protoc-jar-maven-plugin, I would not need to install protobuf and have protoc in my PATH, right?

My error:

mvn clean package
......
......
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.056 s
[INFO] Finished at: 2017-06-27T17:39:01-07:00
[INFO] Final Memory: 18M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (generate-sources) on project session-api: An Ant BuildException has occured: Execute failed: java.io.IOException: Cannot run program "protoc" (in directory "/Users/zliu/git/myApp/myModule1"): error=2, No such file or directory -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command

My pom.xml configuration for the plugin:

            <plugin>
                <groupId>com.github.os72</groupId>
                <artifactId>protoc-jar-maven-plugin</artifactId>
                <version>3.1.0.2</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <protocVersion>2.5.0</protocVersion> <!-- 2.4.1, 2.5.0, 2.6.1, 3.1.0 -->
                            <inputDirectories>
                                <include>src/main/protobuf</include>
                            </inputDirectories>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

I also tried protocVersion with different values. It does not help either. Could anyone help?

Cannot generate gRPC stubs with java-shaded configuration

Tried a dozen different configs and can't seem to get the gRPC stubs to compile. I need the shaded proto code to work with HBase

        <dependency>
            <groupId>com.github.os72</groupId>
            <artifactId>protobuf-java-shaded-351</artifactId>
            <version>0.9</version>
        </dependency>
        <dependency>
        <groupId>com.github.os72</groupId>
        <artifactId>protobuf-java-util-shaded-351</artifactId>
        <version>0.9</version>
        </dependency>    
...
            <plugin>
                    <groupId>com.github.os72</groupId>
                    <artifactId>protoc-jar-maven-plugin</artifactId>
                    <version>3.5.1</version>
                    <executions>
                            <execution>
                                    <phase>generate-sources</phase>
                                    <goals>
                                            <goal>run</goal>
                                    </goals>
                                    <configuration>
                                            <protocVersion>3.5.1</protocVersion>
                                            <!-- <includeStdTypes>true</includeStdTypes> -->
                                            <!-- <protocArtifact>com.google.protobuf:protoc:3.0.0</protocArtifact> -->
                                            <protocArtifact>com.google.protobuf:protoc:3.5.1</protocArtifact>
                                            <inputDirectories>
                                                    <include>src/main/proto</include>
                                            </inputDirectories>
                                            <outputTargets>
                                                    <outputTarget>
                                                            <type>java-shaded</type>
                                                            <outputDirectory>src/main/java</outputDirectory>
                                                    </outputTarget>
                                                    <outputTarget>
                                                            <type>grpc-java</type>
                                                            <outputDirectory>src/main/java</outputDirectory>
                                                            <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.16.1</pluginArtifact>
                                                    </outputTarget>
                                            </outputTargets>
                                    </configuration>
                            </execution>
                    </executions>
            </plugin>  

Output

[ERROR] XXX/src/main/java/com/x/proto/GeneratorGrpc.java:[50,64] method marshaller in class io.grpc.protobuf.ProtoUtils cannot be applied to given types;
[ERROR]   required: T
[ERROR]   found: com.x.proto.Empty
[ERROR]   reason: inferred type does not conform to upper bound(s)
[ERROR]     inferred: com.x.proto.Empty
[ERROR]     upper bound(s): com.google.protobuf.Message

[ERROR] XXX/hbase/src/main/java/com/x/proto/GeneratorGrpc.java:[238,70] getServiceDescriptor() in com.x.proto.GeneratorGrpc.GeneratorBaseDescriptorSupplier cannot implement getServiceDescriptor() in io.grpc.protobuf.ProtoServiceDescriptorSupplier
[ERROR]   return type com.github.os72.protobuf351.Descriptors.ServiceDescriptor is not compatible with com.google.protobuf.Descriptors.ServiceDescriptor
[ERROR] X/hbase/src/main/java/com/x/proto/GeneratorGrpc.java:[233,67] getFileDescriptor() in com.x.proto.DnsGeneratorGrpc.GeneratorBaseDescriptorSupplier cannot implement getFileDescriptor() in io.grpc.protobuf.ProtoFileDescriptorSupplier

I assume I have a version mismatch?

Using proto files which are organized inside directories, but referencing each other, is not possible

Currently the single files are processed inside their parent folders.
I've got a usecase in which the files are inside directories but reference relative to the input directory like following illustration:

  • src
    • main
      • protobuf
        • module_1
          • file1.proto (imports "module_2/file2.proto")
        • module_2
          • file2.proto

The execution fails because "module_2/file2.proto" can't be found inside module_1.
To address this issue a flag could be added which will set the working directory for every protoc execution to the related input directory.
No breaking change needs to be done if the default value is set to false.
I already created a pull request:
Pull Request

Add .proto files to classpath

Is there a way to instruct the plugin to add the .proto files into the JAR at build time? So that the .proto files can be found on the classpath, like in protobuf-java-3.3.1.jar where the standard types are located in google.protobuf.

error=26, Text file busy

During run on CI I get the following error

[ERROR] Failed to execute goal com.github.os72:protoc-jar-maven-plugin:3.1.0.5:run (generate-test-protobuf-sources) on project commons-netty-rest-server: Unable to execute protoc-jar for /var/lib/teamcity/BuildAgents/buildAgent/work/756b569813502e3a/commons/commons-netty-rest/commons-netty-rest-server/src/test/proto/test.proto: Cannot run program "/var/lib/teamcity/BuildAgents/buildAgent/temp/buildTmp/protoc4150673099125997663.exe": error=26, Text file busy -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.os72:protoc-jar-maven-plugin:3.1.0.5:run (generate-test-protobuf-sources) on project commons-netty-rest-server: Unable to execute protoc-jar for /var/lib/teamcity/BuildAgents/buildAgent/work/756b569813502e3a/commons/commons-netty-rest/commons-netty-rest-server/src/test/proto/test.proto
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
	at org.apache.maven.lifecycle.internal.LifecycleThreadedBuilder$1.call(LifecycleThreadedBuilder.java:169)
	at org.apache.maven.lifecycle.internal.LifecycleThreadedBuilder$1.call(LifecycleThreadedBuilder.java:165)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.maven.plugin.MojoExecutionException: Unable to execute protoc-jar for /var/lib/teamcity/BuildAgents/buildAgent/work/756b569813502e3a/commons/commons-netty-rest/commons-netty-rest-server/src/test/proto/test.proto
	at com.github.os72.protocjar.maven.ProtocJarMojo.processFile(ProtocJarMojo.java:443)
	at com.github.os72.protocjar.maven.ProtocJarMojo.processTarget(ProtocJarMojo.java:391)
	at com.github.os72.protocjar.maven.ProtocJarMojo.performProtoCompilation(ProtocJarMojo.java:350)
	at com.github.os72.protocjar.maven.ProtocJarMojo.execute(ProtocJarMojo.java:297)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
	... 11 more
Caused by: java.io.IOException: Cannot run program "/var/lib/teamcity/BuildAgents/buildAgent/temp/buildTmp/protoc4150673099125997663.exe": error=26, Text file busy
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
	at com.github.os72.protocjar.Protoc.runProtoc(Protoc.java:88)
	at com.github.os72.protocjar.Protoc.runProtoc(Protoc.java:61)
	at com.github.os72.protocjar.maven.ProtocJarMojo.processFile(ProtocJarMojo.java:436)
	... 16 more
Caused by: java.io.IOException: error=26, Text file busy
	at java.lang.UNIXProcess.forkAndExec(Native Method)
	at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
	at java.lang.ProcessImpl.start(ProcessImpl.java:134)
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
	... 19 more

For mvn I use -T2C but I believe that it could be raise between different builds on the same agent.
Also it could be result of JDK-8068370 (process) Executing recently modified file results in ETXTBSY

Is it possible to add some retry policy?

Import .proto files from Maven dependencies

Is there a way to import .proto files from Maven dependencies? This would be a practical way to share .proto files between Maven projects.

All I could find is a similar question on Stack Overflow but it is about the maven-protoc-plugin, not this one. This other plugin looks for .proto files in Maven dependencies and put them into a temporary directory. This directory is then set as an import path to the protoc invocation.

It would be great to have a similar feature here :-)

Performance with multiple proto files

Currently protoc is extracted for every every .proto file. This extraction can be rather slow and it would be better to reuse the first extracted protoc for the following files.

It is based around

  • adding runProtoc(String[][] cmds) to protoc-jar (array of array of args), calling runProtoc(cmd, args)
  • calling this new runProtoc from protoc-jar-maven-plugin

Caveat: the protoc-version must be the same for all files. This shouldn't be an issue: if a file(-set) needs a different version, the plugin can be added as often as needed with specific versions into the Maven build.

I have a local patch that needs some refinement - I'll create a PR if you like the idea.

Contribute this Maven plugin to protobuf project

Hi @os72 ,

I was searching for an "official" protobuf plugin for Maven, but I couldn't find any. You did a great job by implementing this version, it seems really useful, but unfortunately since it is not part of the official propobuf project, we can't use it. Did you think of contributing it to protobuf project?

Different output comparing to protobuf-maven-plugin

Different output comparing to org.xolstice.maven.plugins:protobuf-maven-plugin

I just did simple test, and I found that this plugin did not generated GreeterGrpc.java

sources at

image

		<plugins>
			<plugin>
				<groupId>org.xolstice.maven.plugins</groupId>
				<artifactId>protobuf-maven-plugin</artifactId>
				<version>0.5.0</version>
				<configuration>
					<protocArtifact>com.google.protobuf:protoc:3.1.0:exe:${os.detected.classifier}</protocArtifact>
					<pluginId>grpc-java</pluginId>
					<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.1:exe:${os.detected.classifier}</pluginArtifact>
				</configuration>
				<executions>
					<execution>
						<goals>
							<goal>compile</goal>
							<goal>compile-custom</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
		<plugins>
			<plugin>
				<groupId>com.github.os72</groupId>
				<artifactId>protoc-jar-maven-plugin</artifactId>
				<version>3.1.0.1</version>
				<executions>
					<execution>
						<phase>generate-sources</phase>
						<goals>
							<goal>run</goal>
						</goals>
						<configuration>
							<protocVersion>3.1.0</protocVersion>
							<inputDirectories>
								<include>src/main/proto</include>
							</inputDirectories>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>

Use of <includeStdTypes> breaks <protocCommand>

I'm using protoc-jar-maven-plugin to build cross-platform and need to use it on a platform that it doesn't support directly, although protoc itself is available for the platform. I'm using the <protocCommand> tag in the pom.xml to reference the external protoc executable, which all works fine.

The issue is if I also need to use <includeStdTypes>true</includeStdTypes> at the same time. Doing so generates the following error:

[ERROR] Failed to execute goal com.github.os72:protoc-jar-maven-plugin:3.2.0:run (default) on project higgs-management-protocol: Error extracting protoc for version 320: Unsupported platform: sunos/amd64 -> [Help 1]

So why is the plugin trying to extract a copy of protoc when it has been told to use an external version of protoc?

The issue seems to be this line of code:

ProtocJarMojo.java:311

if ((protocCommand == null && protocArtifact == null) || includeStdTypes) {

In this case includeStdTypes is true and the code block following attempts to extract protoc from the plugin JAR, and because the plugin doesn't directly support this platform, it fails to do so and exits with an error.

I believe the logic here is erroneous - if protocCommand and includeStdTypes are both set, no attempt to extract a protoc binary from the JAR should be made and the determination of the -I flag to be added at line 338 should be based on the absolute path of the external protoc command and not the location of the one that is normally extracted from the JAR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.