【问题标题】:Maven Build Number Plugin version not filteredMaven Build Number Plugin 版本未过滤
【发布时间】:2015-02-09 11:10:13
【问题描述】:

我想过滤属性文件中buildnumber-maven-plugin 提供的buildNumber(git 修订号),以便我可以从我的软件中访问它。

我得到了以下 pom:

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>xxxx</groupId>
        <artifactId>xxxx</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <relativePath>..</relativePath>
    </parent>
    <artifactId>xxxx</artifactId>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources/</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <version>1.3</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>create</goal>
                        </goals>
                        <configuration>
                            <shortRevisionLength>5</shortRevisionLength>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

以及后续文件 src/main/resources/revision.properties:

branch = ${scmBranch}
revision = ${buildNumber}
version = ${project.version}

在我运行 mvn clean install 之后,会产生以下输出:

...
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ xxx ---
[INFO] Deleting D:\parsp\git\acm-utils\target
[INFO]
[INFO] --- buildnumber-maven-plugin:1.3:create (default) @ xxx ---
[INFO] ShortRevision tag detected. The value is '5'.
[INFO] Executing: cmd.exe /X /C "git rev-parse --verify --short=5 HEAD"
[INFO] Working directory: D:\parsp\git\acm-utils
[INFO] Storing buildNumber: 70cd7 at timestamp: 1423479895763
[INFO] Storing buildScmBranch: master
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ xxx ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
...

我在 target/classes 中得到以下 resultinf 文件,其中只有 maven 版本被过滤到该文件中:

branch = ${scmBranch}
revision = ${buildNumber}
version = 1.0.0-SNAPSHOT

有什么我错过的吗?

【问题讨论】:

  • 因为它们是由buildnumber-maven-plugin提供的。
  • 顺便说一句:为什么你改变了 buildnumber-maven-plugin 的阶段并且没有保留默认值?删除 buildnumber-maven-plugin 的 &lt;phase&gt;...&lt;/phase&gt; 标签。
  • @khmarbaise buildnumber-maven-plugin 正是我使用的插件(请参阅问题中的 pom 片段)。该片段是从这里复制的:mojo.codehaus.org/buildnumber-maven-plugin/usage.html,其中包括阶段标签。但你是对的,这不是必需的,但它不应该破坏功能,因为在 process-resources 阶段之前,资源被过滤。

标签: git maven


【解决方案1】:

这更像是一种解决方法,而不是一个答案,但我认为 validate 后跟 install 对我有用。但这当然不是实用的使用方法……

在此期间您自己找到解决方案了吗?

【讨论】:

    猜你喜欢
    • 2016-05-18
    • 2020-11-25
    • 2013-04-11
    • 2015-07-11
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    相关资源
    最近更新 更多