为什么在 vscode 中使用 Maven 和 java 时找不到为 grpc 和 protobuf 生成的源文件
why do I not find generated source files for grpc and protobuf when using maven and java in vscode
我有一个 pom 文件,可以在 运行 从命令行正确生成我在 target/generated-sources 中需要的 grpc 和 protobuf 源文件。但是当我在 vscode 中构建时,这些目录是空的并且对 protobufs 的引用是未定义的。这是构建 grpc 源代码的 pom 文件部分。
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
我根据在其他帖子中阅读的内容添加了以下内容,以防止 vscode/eclipse 删除生成的源目录
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/protobuf/grpc-java</source>
<source>/target/generated-sources/protobuf/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
当 vs-code 构建时,目标生成源目录在那里,但其中没有源。我们在使用 intellij 时遇到了类似的问题,但可以通过 运行 在打开 intellij 之前构建 maven 命令行来解决它,但这似乎不适用于 vscode.
改用protoc-jar-maven-plugin
。
示例用法请查看protoc-jar-maven-plugin。
我有一个 pom 文件,可以在 运行 从命令行正确生成我在 target/generated-sources 中需要的 grpc 和 protobuf 源文件。但是当我在 vscode 中构建时,这些目录是空的并且对 protobufs 的引用是未定义的。这是构建 grpc 源代码的 pom 文件部分。
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
我根据在其他帖子中阅读的内容添加了以下内容,以防止 vscode/eclipse 删除生成的源目录
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/protobuf/grpc-java</source>
<source>/target/generated-sources/protobuf/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
当 vs-code 构建时,目标生成源目录在那里,但其中没有源。我们在使用 intellij 时遇到了类似的问题,但可以通过 运行 在打开 intellij 之前构建 maven 命令行来解决它,但这似乎不适用于 vscode.
改用protoc-jar-maven-plugin
。
示例用法请查看protoc-jar-maven-plugin。