Best way to integrate Git with Ant?

后端 未结 7 1048
囚心锁ツ
囚心锁ツ 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: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:

    
        
            
        
    
    

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

提交回复
热议问题