Importing .proto files from a maven dependency?
Asked Answered
B

1

6

Here's my protoc jar plugin -

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

                    <configuration>
                        <protocVersion>${protobuf.version}</protocVersion>

                        <includeStdTypes>true</includeStdTypes>
                        <includeDirectories>
                            <include>src/main/resources</include>
                        </includeDirectories>
                        <inputDirectories>
                            <include>src/main/resources</include>
                        </inputDirectories>

                    </configuration>
                </execution>
            </executions>
        </plugin>

I want to include some import statements from a maven repository available on nexus - which contains a bunch of proto files and their java compiled versions. It's a jar that includes proto files.

How can I include these proto files (packaged in a jar) in the protoc path such that the proto files can be imported in my current working directory?

The issue is that the import keeps failing when I mavenize my project - .proto files cannot be found.

My proto command being used as a part of the protoc looks like - protoc-jar: executing: [C:\protocjar3624070738032398618\bin\protoc.exe, -IC:\protocjar3624070738032398618\include, -IC:myproject\src\main\resources, --java_out=C:\myproject\target\generated-sources, C:\myproject\somedummy.proto]

The command cannot reach out to the com.custom.proto package of the jar that I am importing and I am not sure what to add to the inputDirectories setting in the configuration above to get this package included in the protoc command.

P.S. I am able to use this setting true to get google.protobuf package files included. However, it does not work for other maven dependencies which include proto files (non-standard)

Barrister answered 13/11, 2017 at 13:36 Comment(0)
S
0

Try adding includeMavenTypes directive with either direct or transitive. That execution config works quite well for me:

<execution>
   <phase>generate-sources</phase>
   <goals>
      <goal>run</goal>
    </goals>
    <configuration>
        <protocVersion>3.11.4</protocVersion>                                   
        <includeDirectories>
          <include>src/main/resources</include>
        </includeDirectories>
        <inputDirectories>
          <include>src/main/resources</include>
        </inputDirectories>
        <includeMavenTypes>transitive</includeMavenTypes>
    </configuration>
</execution>
Strainer answered 20/12, 2023 at 11:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.