Raj*_*pta 5 java protocol-buffers maven-plugin maven
我在我的POM中配置了协议缓冲区编译器插件,无论何时构建项目都会执行该插件.这个编译器插件在windows中工作正常但现在我将我的项目移动到ubuntu PC并需要使用合适的替代品.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>compile-protoc</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<mkdir dir="src/main/resources/protocolBuffers/compiled" />
<path id="proto.path">
<fileset dir="src/main/proto">
<include name="**/*.proto" />
</fileset>
</path>
<pathconvert pathsep=" " property="proto.files" refid="proto.path" />
<exec executable="src/main/resources/protocolBuffers/compiler/protoc" failonerror="true">
<arg value="--java_out=src/main/resources/" />
<arg value="-I${project.basedir}/" />
<arg line="${proto.files}"/>
</exec>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
尝试在Ubuntu netbeans中构建项目时,我看到以下输出
--- maven-antrun-plugin:1.3:run (compile-protoc) @ Px10App ---
Executing tasks
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 5.638s
Finished at: Tue Mar 25
Final Memory: 9M/105M
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (compile-protoc) on project Px10App: An Ant BuildException has occured: Execute failed: java.io.IOException: Cannot run program "src/main/resources/protocolBuffers/compiler/protoc": error=2, No such file or directory -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
如何使编译器插件在Ubuntu netbeans中工作?
这个内置protoc(它最初基于igor-petruk/protobuf-maven-plugin,但它带有捆绑用于Linux,Mac/OSX和Windows的protoc二进制文件).在运行时,它会检测平台并执行相应的二进制文件
https://github.com/os72/protoc-jar-maven-plugin
这是一个例子:
<plugin>
<groupId>com.github.os72</groupId>
<artifactId>protoc-jar-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<protocVersion>2.4.1</protocVersion> <!-- 2.4.1, 2.5.0, 2.6.1, 3.2.0 -->
<inputDirectories>
<include>src/main/protobuf</include>
</inputDirectories>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
一个好的跨平台解决方案是使用 Maven Central 中可用的 protoc 二进制工件。
com.google.protobuf.tools: maven-protoc-plugin 文档“Resolving Protoc Artifact From Maven Central Repo”中描述了 pom.xml 所需的简单配置更改
如果链接消失,突出的部分是:
<project>
...
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.3.0.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
<configuration>
<protocArtifact>com.google.protobuf:protoc:2.6.1:exe:${os.detected.classifier}</protocArtifact>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
...
</project>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18317 次 |
| 最近记录: |