Skip to content

Instantly share code, notes, and snippets.

@cqc3073
Last active July 29, 2022 03:03
Show Gist options
  • Save cqc3073/7766447823ac29a70ddeaf403df1f5f6 to your computer and use it in GitHub Desktop.
Save cqc3073/7766447823ac29a70ddeaf403df1f5f6 to your computer and use it in GitHub Desktop.
使用maven自动编译protocol buffer的配置
  • src/main/proto下定义proto文件
  • 在pom.xml中配置
<properties>
    <protobuf.version>3.5.0</protobuf.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.google.protobuf</groupId>
        <artifactId>protobuf-java</artifactId>
        <version>${protobuf.version}</version>
    </dependency>
</dependencies>

<build>
    <extensions>
        <extension>
            <groupId>kr.motd.maven</groupId>
            <artifactId>os-maven-plugin</artifactId>
            <version>1.5.0.Final</version>
        </extension>
    </extensions>
    <plugins>
        <plugin>
            <groupId>org.xolstice.maven.plugins</groupId>
            <artifactId>protobuf-maven-plugin</artifactId>
            <version>0.5.1</version>
            <extensions>true</extensions>
            <configuration>
                <protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
  • 通过mvn compile,就可以在target/generated-sources 下看到生成的源码了
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment