2013-11-25 42 views
0

我想從ANT運行git clone。但似乎像ANT無法找到git可執行文件。我嘗試了以下選項。如何告訴ANT-exec,git可執行文件的位置

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

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

<exec executable="git"> 
+2

'哪個git'說的是什麼命令? –

+0

/usr/bin/git ... – Ahmad

回答

1

您想將位置抽象爲屬性。

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

,然後在exec您指定財產

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

這將允許他人在命令行指定一個不同的位置:

ant -Dgit.executable=/usr/local/bin/git 或者更好的是在一個user.properties文件被源代碼控制忽略,但被導入到build.xml中

T帽子可以回答你的問題,但我想提一提的是,這就像跨越流將源代碼控制系統引用到構建中一樣。你希望這些問題是分開的。構建應該是源代碼控制不可知的。

2

更加可靠的選擇是使用jgit ANT任務:

<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> 

注:

  • 的 「引導」 任務將下載jgit罐子。只需要運行一次。