在Maven中使用maven-surefire-plugin传递系统变量

Joh*_*Doe 10 variables maven

我想为Maven构建传递一些系统变量.如果我使用mvn clean install -Dfirst.variable=value -Dsecond.variable=second.value一切都很好.但是这个配置pom.xml不起作用:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12.3</version>
            <executions>
                <execution>
                    <id>tests</id>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <includes>
                            <include>**/*Test.java</include>
                        </includes>
                        <systemPropertyVariables>
                            <first.variable>${value}</first.variable>
                            <second.variable>${second.value}</second.variable>
                        </systemPropertyVariables>
                    </configuration>
                </execution>
            </executions>
        </plugin> 
Run Code Online (Sandbox Code Playgroud)

我试图用这个配置没有<id/>,<phase/><goals>却没有帮助.插件是否有可能无法运行?甚至这些变量的硬编码值也不会通过.如果是这样,什么是可能的解决方案?提前致谢.

Fab*_*mos 9

你不需要创建一个<execution/>.简单的方法:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
      <systemPropertyVariables>
        <my.property>propertyValue</my.property>
      </systemPropertyVariables>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)