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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM