`protoc-jar-maven-plugin` 无法在同一目录中找到依赖的 proto 文件。

huangapple go评论55阅读模式
英文:

protoc-jar-maven-plugin unable to find dependent proto files in the same directory

问题

我有一个存储所有proto文件的目录,位于${basedir}/resources/proto/,其中有一个名为a.proto的文件,它通过resources/proto/b.proto导入另一个proto文件。我尝试了以下配置,但它的工作方式不如预期:

<plugin>
  <groupId>com.github.os72</groupId>
  <artifactId>protoc-jar-maven-plugin</artifactId>
  <version>3.11.4</version>
  <executions>
    <execution>
      <goals>
        <goal>run</goal>
      </goals>
      <phase>generate-sources</phase>
      <configuration>
        <inputDirectories>
          <include>${basedir}/resources/proto</include>
        </inputDirectories>
        <outputTargets>
          <outputTarget>
            <type>java</type>
            <outputDirectory>${project.build.directory}/generated-sources/java</outputDirectory>
          </outputTarget>
        </outputTargets>
      </configuration>
    </execution>
  </executions>
</plugin>

我相当确定includeDirectories标签只是额外的,不起作用,而我的错误是[ERROR] /home/${basedir}/resources/proto/a.proto [0:0]: resources/proto/b.proto: File not found.

如何正确包含protobuf目录以便进行编译?由于它是一个git子模块,我无法更改proto文件,因此我需要解决当前的情况。

英文:

I have a directory that stores all of my proto files at ${basedir}/resources/proto/, there is a file a.proto in which imports another proto file via resources/proto/b.proto. I tried the following configuration but it does not work as intended:

&lt;plugin&gt;
  &lt;groupId&gt;com.github.os72&lt;/groupId&gt;
  &lt;artifactId&gt;protoc-jar-maven-plugin&lt;/artifactId&gt;
  &lt;version&gt;3.11.4&lt;/version&gt;
  &lt;executions&gt;
    &lt;execution&gt;
      &lt;goals&gt;
        &lt;goal&gt;run&lt;/goal&gt;
      &lt;/goals&gt;
      &lt;phase&gt;generate-sources&lt;/phase&gt;
      &lt;configuration&gt;
        &lt;inputDirectories&gt;
          &lt;include&gt;${basedir}/resources/proto&lt;/include&gt;
        &lt;/inputDirectories&gt;
        &lt;includeDirectories&gt;
          &lt;include&gt;${basedir}/resources/proto&lt;/include&gt;
        &lt;/includeDirectories&gt;
        &lt;outputTargets&gt;
          &lt;outputTarget&gt;
            &lt;type&gt;java&lt;/type&gt;
            &lt;outputDirectory&gt;${project.build.directory}/generated-sources/java&lt;/outputDirectory&gt;
          &lt;/outputTarget&gt;
        &lt;/outputTargets&gt;
      &lt;/configuration&gt;
    &lt;/execution&gt;
  &lt;/executions&gt;
&lt;/plugin&gt;

I'm pretty sure the includeDirectories tag is just extra and does nothing, and my error is [ERROR] /home/${basedir}/resources/proto/a.proto [0:0]: resources/proto/b.proto: File not found.

How can I properly include the protobuf directories so it can compile? I cannot change the proto files as it is a git submodule therefore I need to work around the current situation.

答案1

得分: 1

已解决,包含目录需要直接包含基本目录,因为 Protobuf 文件试图通过完整路径来发现它们。

英文:

Figured it out, include directory needs to directly include the basedir as the protobuf files tries to discover them through the full path.

huangapple
  • 本文由 发表于 2023年4月11日 01:45:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75979406.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定