buildnumber-maven-plugin为scmBranch返回UNKNOWN

时间:2014-02-19 22:39:36

标签: git maven

buildnumber-maven-plugin能够从git获取修订版号,并且根据the meager documentation provided它应该在${scmBranch}属性中提供分支。但是,对于UNKNOWN属性,我得到的只是${scmBranch}

我还需要做些什么才能从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>

1 个答案:

答案 0 :(得分:12)

简短回答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>