简体   繁体   English

BuildNumber不是通过buildnumber-maven-plugin生成的

[英]BuildNumber not generated with buildnumber-maven-plugin

In my parent pom I have 在我的父母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>

In a child module run a java Main class with the above default properties: buildName and scmBranch : 在子模块中,运行具有上述默认属性的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>

But the variables are never substituted/expanded in my main class. 但是变量在我的主类中从未被替换/扩展。 Any ideas? 有任何想法吗?

From the documentation: 从文档中:

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.

As I understand the buildNumber is a property provided when you include the buildnumber-maven-plugin 据我了解, buildNumber是当您包含buildnumber-maven-plugin时提供的属性

In your parent pom, you have not defined the pluginManagement tag. 在父pom中,您尚未定义pluginManagement标记。 Without it, your child module does not inherit the plugins you have defined, they are used by the parent pom only. 没有它,您的子模块将不会继承您定义的插件,它们仅由父pom使用。 This is what you need to add to the parent 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>

Now your child module has access to the buildnumber-maven-plugin. 现在,您的子模块可以访问buildnumber-maven-plugin了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM