Generate-protobuf in Maven

Source: Internet
Author: User

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> &LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.