猿问

专家和Java:如何从测试目录中的原始buf文件生成代码?

我的问题与这个问题非常相似,但对于专家和java。

我正在测试 grpc,并希望在测试/原型文件夹中放入一个简单的 helloworld.proto。

但是,该文件不会生成 java 文件(与 /src/主/原型中的原型文件不同)。

所以我的问题是如何在测试文件夹中为proto生成代码?


慕森卡
浏览 148回答 1
1回答

墨色风雨

首先,按照文档使用组织或者,您可以复制示例 pom.xml(这固定到 v1.19.0 版本,请考虑使用最新的标记)。这个pom被问候世界的例子使用,等等。然后添加原型专家插件的 和 目标。这将导致 生成 中的文件。test-compiletest-compile-customsrc/test/proto&nbsp;<plugin>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.xolstice.maven.plugins</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>protobuf-maven-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>0.5.1</version>&nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <pluginId>grpc-java</pluginId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>&nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; <executions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <execution>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goal>compile</goal>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goal>compile-custom</goal>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goal>test-compile</goal>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goal>test-compile-custom</goal>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </execution>&nbsp; &nbsp; &nbsp; &nbsp; </executions>&nbsp; &nbsp; &nbsp; </plugin>
随时随地看视频慕课网APP

相关分类

Java
我要回答