有两种方法可以将系统属性列表添加到 Surefire:
此配置是已弃用的systemProperties的替换。它可以从 Maven 的属性中接受任何可以转换为 String value 的值。
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<systemPropertyVariables>
<propertyName>propertyValue</propertyName>
<buildDirectory>${project.build.directory}</buildDirectory>
[...]
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project><project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<systemProperties>
<property>
<name>propertyName</name>
<value>propertyValue</value>
</property>
[...]
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>请注意,只有String 值的属性可以作为系统属性传递。任何传递任何其他 Maven 变量类型(即List或URL变量)的尝试都将导致变量表达式按字面意思传递(未计算)。所以有下面的例子:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<systemProperties>
<property>
<name>buildDir</name>
<value>${project.build.outputDirectory}</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>将直接传递${project.build.outputDirectory}因为该表达式的值是File,而不是String。
要从父配置继承“systemProperties”集合,您需要在子 pom 的 systemProperties 节点上指定 combine.children="append":
<systemProperties combine.children="append">
<property>
[...]
</property>
</systemProperties>