eclipse 使用maven配置protobuf-maven-plugin 自动生成java文件及groovy-eclipse插件爬坑
 2019-04-22 16:11:11   511   1   

本文最后更新于天前,文中介绍内容及环境可能已不适用.请谨慎参考.

调研itte api proxy网关下了个waf(web application firewall)项目。

发现里面使用了proto buf,groovy。

挖坑记录.

 

protobuf配置

proto 数据格式定义。 Protocol Buffers,Google的二进制数据传输.

数据传输过程作为序列化为二进制串传输.

 

很早前用过一次,使用的是proto.exe手动转化的java文件,

这次又遇上了,于是用maven解析了一次,直接从仓库拉取对应的proto.exe 解析proto,自动生成java.

 

protobuf-maven-plugin

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

 

 

os-maven-plugin:

自动检测运行系统版本,填入 os.detected.classifier属性,配合protobuf-maven-plugin插件使用,自动从maven仓库下载对应的proto编译器。

生成的属性,可以默认在Properties中指定.

		<!-- <os.detected.classifier>windows-x86_64</os.detected.classifier> -->

 

https://github.com/trustin/os-maven-plugin#generating-a-platform-dependent-dependency

os-maven-plugin eclipse中使用,除了在pom.xml中添加extension,plugin配置外,还需要下载elcipse插件jar包

 

https://github.com/trustin/os-maven-plugin#issues-with-eclipse-m2e-or-other-ides

 Download os-maven-plugin-1.6.1.jar and put it into the <ECLIPSE_HOME>/dropins directory.

 

还需要添加proto 对应的包

<dependency>
  <groupId>com.google.protobuf</groupId>
  <artifactId>protobuf-java</artifactId>
  <version>3.6.1</version>
</dependency>

<dependency>
  <groupId>com.google.protobuf</groupId>
  <artifactId>protobuf-java-util</artifactId>
  <version>3.6.1</version>
</dependency>

 

pom.xml

<build>
		<extensions>
			<extension>
				<groupId>kr.motd.maven</groupId>
				<artifactId>os-maven-plugin</artifactId>
				<version>1.6.1</version>
			</extension>
		</extensions>
....

	<plugins>
<plugin>
				<groupId>kr.motd.maven</groupId>
				<artifactId>os-maven-plugin</artifactId>
				<version>1.6.1</version>
				<executions>
					<execution>
						<phase>initialize</phase>
						<goals>
							<goal>detect</goal>
						</goals>
					</execution>
				</executions>
			</plugin>


			<plugin>
				<groupId>org.xolstice.maven.plugins</groupId>
				<artifactId>protobuf-maven-plugin</artifactId>
				<version>0.5.1</version>
				<configuration>
					<protocArtifact>com.google.protobuf:protoc:3.7.1:exe:${os.detected.classifier}</protocArtifact>
					<pluginId>grpc-java</pluginId>
					<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.20.0:exe:${os.detected.classifier}</pluginArtifact>
				</configuration>
				<executions>
					<execution>
						<goals>
							<goal>compile</goal>
							<goal>compile-custom</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

....

 

完成:

 

会在target/generated-sources 目录自动生成的proto对应的java文件。

 

groovy配置

groovy ,java 脚本插件,暂时一脸懵逼,先弄通了再说。

 

https://github.com/groovy/groovy-eclipse/wiki#releases

eclipse里面使用,一样需要先装插件。

找到对应eclipse升级地址,安装,重启。

 

然后pom配置

<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.8.0</version><!-- 3.6.2 is the minimum -->
				<configuration>

					<source>1.8</source>
					<target>1.8</target>

					<compilerId>groovy-eclipse-compiler</compilerId>
					<compilerArguments>
						<indy /><!-- optional; supported by batch 2.4.12-04+ -->
						<configScript>config.groovy</configScript><!-- optional; supported 
							by batch 2.4.13-02+ -->
					</compilerArguments>
				</configuration>
				<dependencies>
					<dependency>
						<groupId>org.codehaus.groovy</groupId>
						<artifactId>groovy-eclipse-compiler</artifactId>
						<version>3.3.0-01</version>
					</dependency>
					<dependency>
						<groupId>org.codehaus.groovy</groupId>
						<artifactId>groovy-eclipse-batch</artifactId>
						<version>2.5.6-01</version>
					</dependency>
				</dependencies>
			</plugin>

 

 


 2019-04-22 16:56:13 
 0



发表新的评论
{{s_uid}}   , 欢迎回来.
您的称呼(*必填):
您的邮箱地址(*必填,您的邮箱地址不会公开,仅作为有回复后的消息通知手段):
您的站点地址(选填):
留言:

∑( ° △ °|||)︴

(๑•̀ㅂ•́)و✧
<( ̄) ̄)>
[]~( ̄▽ ̄)~*
( ̄ˇ ̄)
[]~( ̄▽ ̄)~*
( ̄ˇ ̄)
╮( ̄▽ ̄)╭
( ̄ε(# ̄)
(⊙ˍ⊙)
( ̄▽ ̄)~*
∑( ° △ °|||)︴

文章分类

可能喜欢 

KxのBook@Copyright 2017- All Rights Reserved
Designed and themed by 野生的喵喵   1343726   38280