Best way to integrate Git with Ant?

后端 未结 7 998
囚心锁ツ
囚心锁ツ 2020-12-24 00:57

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,

相关标签:
7条回答
  • 2020-12-24 01:15

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

    • http://github.com/newtriks/Ant-Funk (and blog post http://www.newtriks.com/?p=910)
    • http://github.com/FrancisVarga/ant-git-macros

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

    0 讨论(0)
  • 2020-12-24 01:20

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

    0 讨论(0)
  • 2020-12-24 01:22

    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.

    0 讨论(0)
  • 2020-12-24 01:32

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

    0 讨论(0)
  • 2020-12-24 01:35

    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 讨论(0)
  • 2020-12-24 01:38

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

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

    0 讨论(0)
提交回复
热议问题