有两种方法可以将系统属性列表添加到 Failsafe:
此配置是已弃用的systemProperies的替换。它可以从 Maven 的属性中接受任何可以转换为字符串值的值
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.6</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-failsafe-plugin</artifactId> <version>2.6</version> <configuration> <systemProperties> <property> <name>propertyName</name> <value>propertyValue</value> </property> [...] </systemProperties> </configuration> <executions> <execution> <id>integration-test</id> <goals> <goal>integration-test</goal> </goals> </execution> <execution> <id>verify</id> <goals> <goal>verify</goal> </goals> </execution> </executions> </plugin> </plugins> </build> [...] </project>
请注意,字符串值属性只能作为系统属性传递。任何传递任何其他 Maven 变量类型(即List或URL变量)的尝试都将导致变量表达式按字面意思传递(未计算)。所以有一个下面的例子:
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.6</version> <configuration> <systemProperties> <property> <name>buildDir</name> <value>${project.build.outputDirectory}</value> </property> </systemProperties> </configuration> <executions> <execution> <id>integration-test</id> <goals> <goal>integration-test</goal> </goals> </execution> <execution> <id>verify</id> <goals> <goal>verify</goal> </goals> </execution> </executions> </plugin> </plugins> </build> [...] </project>
将直接传递${project.build.outputDirectory}因为该表达式的值是File,而不是String。