使用系统属性
有两种方法可以将系统属性列表添加到 Surefire:
系统属性变量
此配置是对已弃用的systemProperties. 它可以接受来自 Maven 属性的任何值,这些值可以转换为 String 值。
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<propertyName>propertyValue</propertyName>
<buildDirectory>${project.build.directory}</buildDirectory>
[...]
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
systemProperties(已弃用)
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemProperties>
<property>
<name>propertyName</name>
<value>propertyValue</value>
</property>
[...]
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
请注意,只有String 类型的属性可以作为系统属性传递。任何传递任何其他 Maven 变量类型(例如 aList或URL变量)的尝试都将导致变量表达式按字面意思传递(未计算)。所以给出下面的例子:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemProperties>
<property>
<name>buildDir</name>
<value>${project.build.outputDirectory}</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
字符串${project.build.outputDirectory}将按字面意思传递,因为该表达式的类型是 a File,而不是 a String。
要从父配置继承systemProperties集合,您需要在子 pom 中combine.children="append"的节点上指定:systemProperties
<systemProperties combine.children="append">
<property>
[...]
</property>
</systemProperties>
特殊 VM 属性
某些系统属性必须在分叉的 VM 的命令行上设置,并且在 VM 启动后无法设置。这些属性必须添加到argLineSurefire 插件的参数中。例如,
<argLine>-Djava.endorsed.dirs=...</argLine>



