49

I am looking for the best way to integrate Git with Ant. Is there a widely used Ant task for Git? Does anyone have any experience using Git through Ant (e.g. dedicated task, exec call, etc)?

1

7 Answers 7

24

Ant supports the exec command that you can use to pass any command (including Git) to the command line for execution. You can always fall back on that.

19

Doesn't look like there were a set of Ant tasks for Git.

This blog talks about some rudimentary tasks for working with Git.

2
13

Here is Git Ant Tasks via JGit: http://aniszczyk.org/2011/05/12/git-ant-tasks-via-jgit/ .

6

Look at JGit-Ant. Unfortunately jgit-ant tasks project hasn't all main git actions, you can find additional info here.

For java developers: you can easily write git-ant-commands yourself with using jgit as in this examples.

1
  • link is broken.
    – Valentino
    Commented Jan 30, 2017 at 15:39
5

It looks like there has been some additional, unofficial work done on Ant tasks for git:

I don't have experience with these, but they appear more fleshed out than tlrobinson's.

0

Use a combination of the JGit library with some <script language="javascript"> code (I used Rhino lubrary but you could equally use Groovy, etc).

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.