GitをAntと統合するための最良の方法を探しています。Gitで広く使用されているAntタスクはありますか?誰かがAntを介してGitを使用した経験がありますか(たとえば、専用タスク、exec呼び出しなど)?
7 に答える
Antは、実行のために任意のコマンド(Gitを含む)をコマンドラインに渡すために使用できるexecコマンドをサポートしています。あなたはいつでもそれに頼ることができます。
Git 用の一連の Ant タスクがあったようには見えません。
このブログでは、Git を操作するためのいくつかの基本的なタスクについて説明します。
JGit-Ant を見てください。残念ながら、jgit-antタスク プロジェクトには、すべての主要な git アクションが含まれているわけではありません。追加情報については、こちらを参照してください。
Java 開発者向け:この例のように、jgitを使用して git-ant-commands を自分で簡単に作成できます。
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 lubrary を使用しましたが、Groovy なども同様に使用できます)。
Time ago I have unsuccessfully looked for ready in use ways to integrate Git and Ant. I needed possibility to create a build with the name of the Git branch. Finally I came to the following solution:
The excerpt from the real build.xml
file:
<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>
The whole content of the file ./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
Invocation is similar to:
ant TARGET options -Dusing.git=
When ${using.git}
is declared, Ant calls the task -check-git-branch-name
to gather the name of a branch (or a commit's number if Git is in detached mode) and generates the build with the appended name of the Git branch (or commit's hnumber), for example build/TARGET-${git-branch-name}
.