在Maven中使用maven-surefire-plugin传递系统变量 [英] Passing system variables with maven-surefire-plugin in Maven

查看:114
本文介绍了在Maven中使用maven-surefire-plugin传递系统变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to pass some system variables for a Maven build. If i use mvn clean install -Dfirst.variable=value -Dsecond.variable=second.value everything's fine. But this configuration in the pom.xml doesn't work:

        <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> 

我尝试在不使用<id/><phase/><goals>的情况下使用此配置,但没有帮助.插件有可能无法运行吗?这些变量的硬编码值都不会通过.如果是这样,什么是可能的解决方案?预先感谢.

I tried to use this config without <id/>, <phase/> and <goals> but it didn't help. Is there a possibility the plugin doesn't run? Even hardcoded values of these variables don't pass. If so, what is a probable solution? Thanks in advance.

推荐答案

您无需创建<execution/>.简单的方法:

You don´t need to create an <execution/>. The easy way:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
      <systemPropertyVariables>
        <my.property>propertyValue</my.property>
      </systemPropertyVariables>
    </configuration>
</plugin>

这篇关于在Maven中使用maven-surefire-plugin传递系统变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆