我的问题非常类似于这个question,但对于maven和java。
我正在测试grpc,并想在test / proto文件夹中放入一个简单的helloworld.proto。
但是该文件不生成java文件(与/ src / main / proto中的proto文件不同)。
所以我的问题是如何在测试文件夹中为proto生成代码?
首先,按照documentation使用org.xolstice.maven.plugins protobuf-maven-plugin。
或者,您可以复制example pom.xml(这是固定到v1.19.0版本;考虑使用最新的标记)。这个pom被helloworld示例使用。
然后为protobuf-maven-plugin添加test-compile
和test-compile-custom
目标。这将导致生成src/test/proto
中的文件。
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protoc.version}: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>
<goal>test-compile</goal>
<goal>test-compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>