There are 2 ways to Generate-protobuf in Maven
1 is a MAVEN plugin that uses PROTOBUF, but the author is the Maven2 plugin for the development, and has not been updated for 2 years
So I chose the second method is to use the Mavn ant plug-in, the entire configuration and ant very much like, a little adjustment can be configured as follows
<plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <EXECUTION&G
T <id>compile-protoc</id> <phase>generate-sources</phase> <configuration&
Gt
<tasks> <mkdir dir= "Src/main/gen-java"/> <path id= "Proto.path" > <fileset dir= "Src/main/proto" > <include name= "**/*.proto"/&
Gt
</fileset> </path> <pathconvert pathsep= "" property= "Proto.files"
Refid= "Proto.path"/> <exec executable= "Protoc" > <arg value= "--java_out=src/main/gen-java"/> <arg value= "-i${project.basedir}/src/mai
N/proto "/> <arg line=" ${proto.files} "/> </exec> </tasks> <sourceroot>src/main/gen-java</sourceroo
t> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin>
The lifecycle is tied to generate-sources, as long as Maven generate-sources is executed.
The proto file is placed under MAVEN's specifications under the Src/main/proto folder, and the resulting Java file is Src/main/gen-java
Automatically generated files will have to be automatically deleted
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
< verbose>true</verbose>
<filesets>
<fileset>
<directory>src/main/ gen-java</directory>
</fileset>
</filesets>
</configuration>
</ Plugin>
Delete the Gen-java folder while executing maven clean