How to tell ANT-exec, the location of git executable

浪子不回头ぞ 提交于 2019-12-11 21:47:19

问题


I am trying to run git clone from ANT. But seems like ANT is not able to find git executable. I have tried following options.

<exec executable="/opt/freeware/bin/git">

<exec executable="/usr/bin/git">

<exec executable="git">

回答1:


A more robust option is to use the jgit ANT task:

<project name="demo" default="clone">

  <target name="bootstrap">
    <mkdir dir="${user.home}/.ant/lib"/>
    <get dest="${user.home}/.ant/lib/jgit.jar" src="http://search.maven.org/remotecontent?filepath=org/eclipse/jgit/org.eclipse.jgit/3.1.0.201310021548-r/org.eclipse.jgit-3.1.0.201310021548-r.jar"/>
    <get dest="${user.home}/.ant/lib/jgit.ant.jar" src="http://search.maven.org/remotecontent?filepath=org/eclipse/jgit/org.eclipse.jgit.ant/3.1.0.201310021548-r/org.eclipse.jgit.ant-3.1.0.201310021548-r.jar"/>
    <get dest="${user.home}/.ant/lib/jsch.jar" src="http://search.maven.org/remotecontent?filepath=com/jcraft/jsch/0.1.50/jsch-0.1.50.jar"/>
  </target>

  <target name="clone">
    <taskdef resource="org/eclipse/jgit/ant/ant-tasks.properties"/>
    <git-clone uri="https://github.com/myproject/myrepo.git" dest="build/myrepo" branch="master"/>
  </target>

  <target name="clean">
    <delete dir="build"/>
  </target>

</project>

Notes:

  • The "bootstrap" task will download the jgit jars. Only needs to be run once.



回答2:


you want to abstract the location into a property.

<property name="git.executable" value="/usr/bin/git" />

and then in your exec you specify that property

<exec executable="${git.executable}">

This will allow others to specify a different location from the commandline:

ant -Dgit.executable=/usr/local/bin/git Or better yet in a user.properties file that is ignored by source control but imported into your build.xml

That answers your question, but I want to mention that it's like crossing the streams to put references to your source control system in your build. You want those concerns to be separate. The build should be source control agnostic.



来源:https://stackoverflow.com/questions/20195407/how-to-tell-ant-exec-the-location-of-git-executable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!