【问题标题】:BuildNumber not generated with buildnumber-maven-pluginBuildNumber 不是用 buildnumber-maven-plugin 生成的
【发布时间】:2012-12-20 21:53:04
【问题描述】:

在我的父母 pom 我有

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

在子模块中运行具有上述默认属性的 java Main 类:buildNamescmBranch

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
    <execution>
        <id>my-execution</id>
        <phase>package</phase>
        <goals>
            <goal>exec</goal>
            </goals>
        </execution>
        </executions>
            <configuration>
            <executable>java</executable>
                <arguments>
                    <argument>-classpath</argument>
                        <classpath />
                        <argument>${MyMainClass}</argument>
                        <argument>test-${scmBranch}-${buildNumber}</argument>
                </arguments>
            </configuration>

但变量在我的主类中从未被替换/扩展。有什么想法吗?

来自文档:

required: false
type: java.lang.String
expression: ${maven.buildNumber.buildNumberPropertyName}
default: buildNumber

You can rename the buildNumber property name to another 
 property name if desired.

据我了解,buildNumber 是包含 buildnumber-maven-plugin 时提供的属性

【问题讨论】:

  • 属性 scmBranch 和 buildNumber 定义在哪里?你能把那个代码也贴一下吗?
  • 据我了解,它们是在您使用插件时提供的
  • 你的 pom 中定义了&lt;scm&gt; 块吗?这是构建号插件了解如何与源代码控制系统通信所必需的。另外,我建议您为&lt;revisionOnScmFailure&gt; 设置一个值,这样当出现问题时您可以很容易地看到一个错误的值,例如&lt;revisionOnScmFailure&gt;didn't work!&lt;/revisionOnScmFailure&gt;。另外,你能粘贴maven的输出吗?内部版本号插件应该记录一些关于它在调用时所做的事情的信息。
  • 能不能把生命周期阶段的定义去掉,使用插件默认的生命周期阶段重新勾选?你怎么叫 mvn ? mvn clean package ?
  • 从生命周期中删除什么都不做,是的,我使用 mvn clean package 构建

标签: java maven


【解决方案1】:

在你的父 pom 中,你还没有定义 pluginManagement 标签。没有它,您的子模块不会继承您定义的插件,它们仅由父 pom 使用。这是您需要添加到 父 pom 的内容:

<build>
    <!-- plugins used by this POM and all inheriting POMs -->
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>create</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <doCheck>true</doCheck>
                    <doUpdate>true</doUpdate>
                </configuration>
            </plugin>
            <!-- other plugins -->
        </plugins>
    </pluginManagement>
</build>

现在您的子模块可以访问 buildnumber-maven-plugin。

【讨论】:

  • 试过这个提议,但没有奏效。 ${buildNumber} 未传播,保持“null”。
  • 您好,您是否在您孩子的 中声明 buildnumber-maven-plugin?您只需要重新声明 groupId 和 artifactId,其余的都是继承的。
  • 在对我的 pom 进行拉取、重组、弄乱等之后,我必须收回我之前的声明。您的示例效果很好,我现在喜欢 build.properties 中所有子模块 jar 中的提交 id。
  • 太棒了!随时使用任何缺失的信息编辑我的答案。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-20
相关资源
最近更新 更多