在Eclipse IDE中使用Maven / m2e从.proto自动生成Java
问题内容:
对于我的团队,我想配置maven /
eclipse构建以从*.proto
文件自动生成Java代码(在使用gRPC的项目中)。当前需要运行mvn generate-source
或mvn protobuf:compile
(如在插件使用情况页面中)。或添加运行配置以调用maven目标是什么compile
?
每当刷新Eclipse Maven项目(Alt
+
F5
)或重新启动IDE时,都会重新构建项目,但项目中不会出现target/generated
,从而使项目变成红色。因此,需要生成并刷新项目(F5
)。UPDATE
Eclipse需要在.clathpath
文件中配置源文件夹。
据我所知,它应该是m2e连接器,但是我只能为最古老的Google 找到一个https://github.com/masterzen/m2e-protoc-
connector,s plugin com.google.protobuf.tools:maven-protoc- plugin
目前在https://github.com/上也没有提到grpc
/ grpc-java
我们使用完全引用/推荐的
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
那是:
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.1.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.1.0:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.1:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
有关:
- 看了这个,但是那个作者正在使用其他较旧的,现在不支持的插件:由protobuf生成的代码引起的Eclipse构建循环(与Maven Project Builder有关)
PPS该插件https://github.com/igor-petruk/protobuf-
maven-但是插件的延续形式为https://github.com/os72/protoc-jar-maven-
plugin
问题答案:
对于protobuf-maven-plugin
感谢sergei-ivanov在https://github.com/xolstice/protobuf-maven-
plugin/issues/16中的
回答,这给出了链接https://github.com/trustin/os-maven-plugin#issues-
with- eclipse-m2e-or-other-ides:
需要下载os-maven-plugin-
xxxFinal.jar(与pomx.ml中的版本相同)并将其放入<ECLIPSE_HOME>/plugins
目录中。
之后,Eclipse将在项目清理中生成源代码,包括在Maven -update project …(Alt
+
F5
)之后,但不在Project-> Build(或使用默认的自动生成)之后。同样在IDE启动时,它将无法编译。
是的,这是不合逻辑的:
Project-Clean将生成并编译Java源代码,
而 Project-Build将不会 生成和编译Java源代码
。
PS 引发错误507412