2014-02-19 424 views
5

buildnumber-maven-plugin能夠從git獲取修訂號並根據the meager documentation provided它應該提供分支以及${scmBranch}屬性。但是,我所得到的全部爲UNKNOWN,屬於${scmBranch}屬性。buildnumber-maven-plugin正在爲scmBranch返回UNKNOWN

有什麼我需要做的從buildnumber-maven-plugin獲取分支信息嗎?

下面是我的pom.xml中的相關條目:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>buildnumber-maven-plugin</artifactId> 
    <version>1.2</version> 
    <executions> 
     <execution> 
      <phase>validate</phase> 
      <goals> 
       <goal>create</goal> 
      </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <doCheck>true</doCheck> 
     <doUpdate>true</doUpdate> 
    </configuration> 
</plugin> 

<manifestEntries> 
    <Build-Branch>${scmBranch}</Build-Branch> 
    <Build-Revision>${buildNumber}</Build-Revision> 
    <Build-Timestamp>${maven.build.timestamp}</Build-Timestamp> 
</manifestEntries> 
+0

如果你有微薄的文檔的意見爲什麼不[創建一個問題( http://jira.codehaus.org/browse/MBUILDNUM)或最好提出如何改進文檔或爲文檔創建補丁的建議。 – khmarbaise

+0

當我將文檔稱爲「微薄」時,我正在外交。鑑於下面的答案,我應該把它稱爲誤導。這個插件的作者必須知道它只適用於SVN,所以創建一個問題只會告訴他們他們已經知道,但沒有文檔:buildnumber-maven-plugin與svn協同工作,而不是與git協同工作。 –

+0

那麼爲什麼不作出更好的建議如何記錄它呢? – khmarbaise

回答

11

簡短的回答了buildnumber插件1.2 doesn't print git branches,所以檢查出jgit-buildnumbermaven-git-commit-id插件。


不管你多麼配置它,你不會得到一個分支出來的buildnumber插件1.2,因爲它只是在尋找SVN branch information

反而有大量的社區貢獻git plugins for maven

下面是一個使用所有這三個插件的實例爲例POM,您可以快速地嘗試通過mvn -f test.xml validate

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>my.test</groupId> 
    <artifactId>git-branch-info</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 

    <scm> 
     <connection>scm:git:ssh://path_not_used_in_buildnumber_example/but_scm_type_is</connection> 
    </scm> 

    <build> 
     <plugins> 

      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>buildnumber-maven-plugin</artifactId> 
       <version>1.2</version> 
       <executions> 
        <execution> 
         <phase>validate</phase> 
         <goals> 
          <goal>create</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 

      <plugin> 
       <groupId>ru.concerteza.buildnumber</groupId> 
       <artifactId>maven-jgit-buildnumber-plugin</artifactId> 
       <version>1.2.7</version> 
       <executions> 
        <execution> 
         <id>jgit-buildnumber</id> 
         <goals> 
          <goal>extract-buildnumber</goal> 
         </goals> 
         <phase>validate</phase> 
        </execution> 
       </executions> 
      </plugin> 

      <plugin> 
       <groupId>pl.project13.maven</groupId> 
       <artifactId>git-commit-id-plugin</artifactId> 
       <version>2.1.9</version> 
       <executions> 
        <execution> 
         <id>git-commit-id</id> 
         <goals> 
          <goal>revision</goal> 
         </goals> 
         <phase>validate</phase> 
         <configuration> 
          <!-- Only changing prefix since properties conflicts with jgit above --> 
          <prefix>git-commit-id</prefix> 
          <!-- We're using a pom in this example--> 
          <skipPoms>false</skipPoms> 
          <gitDescribe> 
           <!-- Faster to get just branch if skip = true --> 
           <skip>false</skip> 
          </gitDescribe> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-antrun-plugin</artifactId> 
       <version>1.7</version> 
       <executions> 
        <execution> 
         <id>echo-properties</id> 
         <goals> 
          <goal>run</goal> 
         </goals> 
         <phase>validate</phase> 
         <configuration> 
          <target> 
           <echo message="buildnumber-maven-plugin properties:"/> 
           <echo message=" $${scmBranch}:     ${scmBranch}" /> 
           <echo message=" $${buildNumber}:    ${buildNumber}" /> 
           <echo message=" $${timestamp}:     ${timestamp}" /> 

           <echo message="maven-jgit-buildnumber-plugin properties:"/> 
           <echo message=" $${git.revision}:    ${git.revision}" /> 
           <echo message=" $${git.branch}:     ${git.branch}" /> 
           <echo message=" $${git.tag}:     ${git.tag}" /> 
           <echo message=" $${git.commitsCount}:   ${git.commitsCount}" /> 
           <echo message=" $${git.buildnumber}:   ${git.buildnumber}" /> 


           <echo message="git-commit-id-plugin properties (aliased with git-commit-id):"/> 
           <echo message=" $${git.branch}:     ${git-commit-id.branch}" /> 

           <echo message=" $${git.commit.id.describe}:  ${git-commit-id.commit.id.describe}" /> 

           <echo message=" $${git.build.user.name}:  ${git-commit-id.build.user.name}" /> 
           <echo message=" $${git.build.user.email}:  ${git-commit-id.build.user.email}" /> 
           <echo message=" $${git.build.time}:    ${git-commit-id.build.time}" /> 

           <echo message=" $${git.commit.id}:    ${git-commit-id.commit.id}" /> 
           <echo message=" $${git.commit.id.abbrev}:  ${git-commit-id.commit.id.abbrev}" /> 
           <echo message=" $${git.commit.user.name}:  ${git-commit-id.commit.user.name}" /> 
           <echo message=" $${git.commit.user.email}:  ${git-commit-id.commit.user.email}" /> 
           <echo message=" $${git.commit.message.full}: ${git-commit-id.commit.message.full}" /> 
           <echo message=" $${git.commit.message.short}: ${git-commit-id.commit.message.short}" /> 
           <echo message=" $${git.commit.time}:   ${git-commit-id.commit.time}" /> 
          </target> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

     </plugins> 
    </build> 

</project> 
+1

您的第一個鏈接在上面 - 哈哈!他們如何編寫這樣的代碼,然後聲稱該插件可以與git一起工作是令人難以置信的。 jgit-buildnumber做我需要的。謝謝。 –

+3

jgit-buildnumber不檢查未提交的更改。爲了得到這個檢查,我必須將buildnumber-maven-plugin添加回pom.xml,仍然使用jgit-buildnumber作爲清單條目。最好的兩個插件。 –

+7

插件v1.3將打印git分支名稱。 – cslotty

相關問題