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

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

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

猜你喜欢

转载自www.cnblogs.com/029zz010buct/p/9235419.html
今日推荐