maven - ${surefire.forkNumber} 总是解析为 null

标签 maven

我在 pom 的系统属性中使用 ${surefire.forkNumber} 。根据maven documentation ,它应该被解析为当前正在运行的 fork 的数量。但它解析为 null。
下面是我的 pom 文件的片段:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.16</version>
                <configuration>
                    <forkCount>3</forkCount>
                    <reuseForks>true</reuseForks>
                    <redirectTestOutputToFile>true</redirectTestOutputToFile>
                    <systemPropertyVariables>
                         <database.name>My_Test_Schema_${surefire.forkNumber}</database.name>
                    </systemPropertyVariables>
                </configuration>
</plugin>

我错过了什么吗?

拜托,任何人都可以抛出一些光......

最佳答案

${surefire.forkNumber} 可能被替换两次:首先被 maven-core 替换,然后被 surefire 替换。由于 maven-core 不知道这个属性,它在那里替换了 null

解决方案:通过引用 $ 防止首次替换:

<systemPropertyVariables>
    <database.name>My_Test_Schema_$${surefire.forkNumber}</database.name>
</systemPropertyVariables>

来源:http://maven.40175.n5.nabble.com/SureFire-2-16-doesn-t-respect-forkCount-td5771850.html#a5771855

这个对我有用 --- 我遇到了同样的问题。很遗憾,这没有记录在案。

关于maven - ${surefire.forkNumber} 总是解析为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22144287/

相关文章:

java - Maven 构建因 Spring-cloud-contract-verifier 而失败

java - 无法使用maven用java和scala编译spring boot项目

java - 无法加载委托(delegate)类 : org.quartz.impl.jdbcjobstore.oracle.OracleDelegate

java - tomcat7 maven插件WebApplicationInitializer错误

Jenkins 中的 Maven 包装器

java - 运行 Spring XML 时构建失败

java - 无法使用 classLoader.getResource(fileName).getFile() 获取文件

maven - Jenkins构建错误致命TALT : Couldn’t find any executable in C:\apache-maven-3.5.0\bin

java - 三个maven项目A依赖B,B依赖C,如何让C在编译时对A不可见?

maven - Apache 光束 :'Unable to find registrar for hdfs'