在我的父母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类: buildName 和 scmBranch :
<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时提供的属性
答案 0 :(得分:2)
在您的父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。