使用系统属性

有两种方法可以将系统属性列表添加到 Failsafe:

系统属性变量

此配置是已弃用的systemProperties的替换。它可以从 Maven 的属性中接受任何可以转换为 String value 的值

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.12.4</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.12.4</version>
        <configuration>
          <systemProperties>
            <property>
              <name>propertyName</name>
              <value>propertyValue</value>
            </property>
            [...]
          </systemProperties>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

请注意,只有String 值的属性可以作为系统属性传递。任何传递任何其他 Maven 变量类型(即ListURL变量)的尝试都将导致变量表达式按字面意思传递(未计算)。所以有下面的例子:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.12.4</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>

特殊 VM 属性

某些系统属性必须在分叉的 VM 的命令行上设置,并且在 VM 启动后无法设置。这些属性必须添加到 surefire 插件的 argLine 参数中。

  <argLine>-Djava.endorsed.dirs=...</argLine>