Integrate Protocol Buffers into Maven2 build

前端 未结 9 680
悲哀的现实
悲哀的现实 2021-01-30 02:18

I\'m experimenting with Protocol Buffers in an existing, fairly vanilla Maven 2 project. Currently, I invoke a shell script every time I need to update my generated sources. Thi

相关标签:
9条回答
  • 2021-01-30 03:11

    I think that using antrun to invoke non-Maven steps is the generally accepted solution.

    You could also try the maven-exec-plugin.

    0 讨论(0)
  • 2021-01-30 03:12

    I forked of the plugin from David Trott and have it compiling multiple languages which makes it a lot more useful. See the github project here and a tutorial on integrating it with a maven build here.

    0 讨论(0)
  • 2021-01-30 03:15

    The accepted solution does not scale for multiple proto files. I had to come up with my own:

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>compile-protoc</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <tasks>
                                <mkdir dir="${generated.sourceDirectory}" />
                                <path id="proto.path">
                                    <fileset dir="src/main/proto">
                                        <include name="**/*.proto" />
                                    </fileset>
                                </path>
                                <pathconvert pathsep=" " property="proto.files" refid="proto.path" />
                                <exec executable="protoc" failonerror="true">
                                    <arg value="--java_out=${generated.sourceDirectory}" />
                                    <arg value="-I${project.basedir}/src/main/proto" />
                                    <arg line="${proto.files}" />
                                </exec>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    </build>
    
    0 讨论(0)
提交回复
热议问题