我正在寻找将 Git 与 Ant 集成的最佳方式。Git 是否有广泛使用的 Ant 任务?有没有人有通过 Ant 使用 Git 的经验(例如专用任务、执行调用等)?
7 回答
Ant 支持exec 命令,您可以使用该命令将任何命令(包括 Git)传递到命令行以执行。你总是可以依靠它。
看起来 Git 没有一组 Ant 任务。
该博客讨论了使用 Git 的一些基本任务。
这是通过 JGit 的 Git Ant 任务:http: //aniszczyk.org/2011/05/12/git-ant-tasks-via-jgit/。
看看 JGit-Ant。不幸的是,jgit-ant任务项目并没有所有主要的 git 操作,您可以在此处找到更多信息。
看起来在 git 的 Ant 任务上做了一些额外的、非官方的工作:
- http://github.com/newtriks/Ant-Funk(和博客文章http://www.newtriks.com/?p=910)
- http://github.com/FrancisVarga/ant-git-macros
我没有这些经验,但它们看起来比 tlrobinson 的更充实。
将 JGit 库与一些<script language="javascript">
代码结合使用(我使用了 Rhino 库,但您同样可以使用 Groovy 等)。
前段时间我没有成功地寻找集成 Git 和 Ant 的现成可用方法。我需要使用 Git 分支的名称创建构建的可能性。最后我得出了以下解决方案:
build.xml
真实文件的摘录:
<target name="-check-git-branch-name"
if="using.git"
>
<exec executable="bash" logError="true" failonerror="true"
outputproperty="git-branch-name">
<arg value="./bin/git-branch-name.sh" />
</exec>
</target>
文件的全部内容./bin/git-branch-name.sh
#!/bin/bash
# This script is the part of integration GIT to ANT. Once launched it
# should return the name of the current branch or the current commit (if
# GIT is the detached HEAD mode). Further the printed name is appended to
# the name of the resulting directory. To initialize this feature you need
# to run ANT with the option "-Dusing.git=".
exec 2>/dev/null
git rev-parse --abbrev-ref HEAD | grep -v HEAD || git rev-parse HEAD
调用类似于:
ant TARGET options -Dusing.git=
声明时${using.git}
,Ant 调用任务-check-git-branch-name
来收集分支的名称(或如果 Git 处于分离模式,则为提交的编号)并生成带有 Git 分支的附加名称(或提交的 hnumber)的构建,例如build/TARGET-${git-branch-name}
.