java - BuildNumber 不是由 buildnumber-maven-plugin 生成的

标签 java maven

在我的父 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 主类: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 时提供的属性

最佳答案

在你的父 pom 中,你没有定义 pluginManagement标签。没有它,您的子模块不会继承您定义的插件,它们仅由父 pom 使用。这是您需要添加到 parent 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。

关于java - BuildNumber 不是由 buildnumber-maven-plugin 生成的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13981120/

相关文章:

java - 创建的 String 对象的数量

java - Spring Boot和Hibernate : for org. springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor

Java 8 支持 Jersey 框架

android - Gradle 尝试从错误的存储库下载

java - 如何在 Java 7 中启用 TLSv1.2?

maven - 第一次 mvn 原型(prototype) :generate failed

java - 如何序列化 BigDecimal 以与 jackson 映射值?

java - 如何使用大括号在java中分割以下字符串

java - ASM Tree API 插入 InsnList 会出现 StackOverflowError?

java - Storm KafkaSpout 停止消费来自 Kafka Topic 的消息