maven中进行go的编译

maven提供的插件maven-antrun-plugin真是个好东东,使得maven可以利用ant的很多功能。

最近需要实现在maven中实现对go代码的编译,添加如下代码在pom文件中即可。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>go-build</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<exportAntProperties>true</exportAntProperties>
<target name="build hermes">
<exec executable="go" dir="${basedir}/src/go/hermes">
<arg value="build"/>
</exec>
<echo message="go build hermes successfully!" level="info"/>
</target>
</configuration>
</execution>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy file="/${basedir}/src/go/hermes/hermes"
tofile="../bin/hermes" overwrite="true"/>
<echo message="copy hermes successfully!" level="info"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>

failonerror:表示当出现错误时自动停止

 

arg例子 
<arg value="-l -a"/> 
是一个含有空格的单个的命令行变量。 
<arg line="-l -a"/> 
是两个空格分隔的命令行变量。 
<arg path="/dir;/dir2:\dir3"/> 
是一个命令行变量,其值在DOS系统上为\dir;\dir2;\dir3;在Unix系统上为/dir:/dir2:/dir3 。



上面包括两部分,第一步是go代码的编译,第二部是将起copy到别的地方,都利用这个插件完成,虽然不是最优美的方式,但的确完成了任务。

应该说,ant中可以做的事情,都可以通过这种方式来进行。

参见:https://maven.apache.org/plugins/maven-antrun-plugin/usage.html

转载于:https://www.cnblogs.com/029zz010buct/p/9235419.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值