代码之家  ›  专栏  ›  技术社区  ›  Max A.

将协议缓冲区集成到Maven2构建中

  •  42
  • Max A.  · 技术社区  · 16 年前

    1. branch on Google Code 其作者似乎已经尝试实现了这样一个插件。不幸的是,它 hasn't passed code review 或者被合并到原蟾蜍的躯干中。因此,该插件的状态未知。

    2. protoc antrun 调用或类似的东西。

    个人经历最受赞赏。

    9 回复  |  直到 16 年前
        1
  •  44
  •   Donal Fellows    14 年前

    您可以在Protocol Buffers存储库中找到有关该插件的一些信息 Protocol Buffers Compiler Maven Plug-In Protocol Buffers讨论组上的主题。我的理解是,它是可用的,但缺乏测试。我会试试的。

    或者你可以直接使用 antrun 插件(从上面提到的线程粘贴的狙击):

     <build>
       <plugins>
         <plugin>
           <artifactId>maven-antrun-plugin</artifactId>
           <executions>
             <execution>
               <id>generate-sources</id>
               <phase>generate-sources</phase>
               <configuration>
                 <tasks>
                   <mkdir dir="target/generated-sources"/>
                   <exec executable="protoc">
                     <arg value="--java_out=target/generated-sources"/>
                     <arg value="src/main/protobuf/test.proto"/>
                   </exec>
                 </tasks>
                 <sourceRoot>target/generated-sources</sourceRoot>
               </configuration>
               <goals>
                 <goal>run</goal>
               </goals>
             </execution>
           </executions>
         </plugin>
       </plugins>
     </build>
    
     <dependencies>
       <dependency>
         <groupId>com.google.protobuf</groupId>
         <artifactId>protobuf-java</artifactId>
         <version>2.0.3</version>
       </dependency>
     </dependencies>
    
        2
  •  23
  •   Community Mohan Dere    9 年前

    accepted answer 鼓励我使用谷歌提供的插件。我将问题中提到的分支合并到2.2.0源代码的签出中,构建并安装/部署了插件,并能够在我的项目中使用它,如下所示:

      <build>
        <plugins>
          <plugin>
            <groupId>com.google.protobuf.tools</groupId>
            <artifactId>maven-protoc-plugin</artifactId>
            <version>0.0.1</version>
            <executions>
              <execution>
                <id>generate-sources</id>
                <goals>
                  <goal>compile</goal>
                </goals>
                <phase>generate-sources</phase>
                <configuration>
                  <protoSourceRoot>${basedir}/src/main/protobuf/</protoSourceRoot>
                  <includes>
                    <param>**/*.proto</param>
                  </includes>
                </configuration>
              </execution>
            </executions>
            <configuration>
              <protocExecutable>/usr/local/bin/protoc</protocExecutable>
            </configuration>
          </plugin>
        </plugins>
      </build>
    

        3
  •  21
  •   Donal Fellows    14 年前

    <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>
    
        4
  •  10
  •   Anthony O.    13 年前
        5
  •  4
  •   mrm    16 年前

    我刚刚更新了maven插件,使其与2.2.0兼容——更新后的pom附加到了代码审查bug中。

    以下是自己构建插件的说明:

    svn co http://protobuf.googlecode.com/svn/branches/maven-plugin/tools/maven-plugin
    cd maven-plugin
    wget -O pom.xml 'http://protobuf.googlecode.com/issues/attachment?aid=8860476605163151855&name=pom.xml'
    mvn install
    

        6
  •  4
  •   ndolgov    15 年前

    我刚刚尝试了一个不太官方但很新的(v 0.1.7)fork https://github.com/dtrott/maven-protoc-plugin

    <temporaryProtoFileDirectory>${basedir}/target/temp</temporaryProtoFileDirectory>

    紧接着

    <protocExecutable>protoc</protocExecutable> .

        7
  •  4
  •   vr3C    9 年前

    https://www.xolstice.org/protobuf-maven-plugin/usage.html

    最小配置

     <plugin>
        <groupId>org.xolstice.maven.plugins</groupId>
        <artifactId>protobuf-maven-plugin</artifactId>
        <version>0.5.0</version>
        <configuration>
          <protocExecutable>/usr/local/bin/protoc</protocExecutable>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>test-compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    
        8
  •  0
  •   matt b    16 年前
        9
  •  0
  •   Usman Ismail    14 年前