如何将分支转换为清单

时间:2016-11-18 23:38:00

标签: git maven buildnumber-maven-plugin

使用buildnumber maven插件,我想将分支存储在我的jar清单中。我尝试了两种不同的方式,如下所示。

以下是我的构建的输出(仅限相关部分) [INFO] --- buildnumber-maven-plugin:1.4:create (default) @ myproject --- [INFO] ShortRevision tag detected. The value is '7'. [INFO] Executing: /bin/sh -c cd '/workspace/myproject' && 'git' 'rev-parse' '--verify' '--short=7' 'HEAD' [INFO] Working directory: /workspace/myproject [INFO] Storing buildNumber: ed5ea17 at timestamp: 1479511476753 [INFO] Storing buildScmBranch: bug/abuginthesystem

这里是尝试1的插件部分(来自插件网站的SCMBranch键): <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> <version>1.4</version> <executions> <execution> <phase>validate</phase> <goals> <goal>create</goal> </goals> </execution> </executions> <configuration> <doCheck>false</doCheck> <doUpdate>false</doUpdate> <shortRevisionLength>7</shortRevisionLength> </configuration> </plugin> <plugin> <artifactId>maven-jar-plugin</artifactId> <version>2.6</version> <configuration> <archive> <manifestEntries> <Build-OS>${os.name} ${os.version}</Build-OS> <Build-Java>Java ${java.version}</Build-Java> <Build-Number>${buildNumber}</Build-Number> <Build-Branch>${SCMBranch}</Build-Branch> </manifestEntries> </archive> </configuration> </plugin>

使用构建尝试2: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> <version>1.4</version> <executions> <execution> <phase>validate</phase> <goals> <goal>create</goal> </goals> </execution> </executions> <configuration> <doCheck>false</doCheck> <doUpdate>false</doUpdate> <shortRevisionLength>7</shortRevisionLength> </configuration> </plugin> <plugin> <artifactId>maven-jar-plugin</artifactId> <version>2.6</version> <configuration> <archive> <manifestEntries> <Build-OS>${os.name} ${os.version}</Build-OS> <Build-Java>Java ${java.version}</Build-Java> <Build-Number>${buildNumber}</Build-Number> <Build-Branch>${buildScmBranch}</Build-Branch> </manifestEntries> </archive> </configuration> </plugin>

两者的清单输出是: Manifest-Version: 1.0 Build-Java: Java 1.7.0_79 Build-Number: ed5ea17 Build-OS: Linux 4.4.0-47-generic Built-By: mondain Build-Jdk: 1.7.0_79 Build-Branch: Created-By: Apache Maven 3.3.9 Archiver-Version: Plexus Archiver

1 个答案:

答案 0 :(得分:2)

如果您想在manifestEntries中使用以下内容:

<Build-Branch>${buildScmBranch}</Build-Branch>

然后,您应该在buildnumber-maven-plugin的配置中使用以下内容:

<plugin>
    <artifactId>buildnumber-maven-plugin</artifactId>
  ...
    <configuration>
        <scmBranchPropertyName>buildScmBranch</scmBranchPropertyName>
      ...