Maven。轮廓。属性和System.getProperty()

Ser*_*nin 3 java groovy maven

我想使用不同的Maven配置文件来设置不同的参数以满足测试需求。参数是URL。测试是在Groovy上进行的。我正在尝试:

<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <useUrl>http://url</useUrl>
        </properties>
    </profile>

    <profile>
        <id>another</id>
        <properties>
            <useUrl>http://url2</useUrl>
        </properties>
    </profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)

和常规代码: baseUrl = System.getProperty("useUrl")

System.getProperty("useUrl") 始终返回“ null”。

但是,如果我在surefire插件中进行如下配置:

<systemPropertyVariables>
    <baseUrl>${useUrl}</baseUrl>
</systemPropertyVariables>
Run Code Online (Sandbox Code Playgroud)

代码System.getProperty("useUrl")将完全返回我期望的值-活动配置文件(http://urlhttp://url2)中的值。

系统信息:Maven 3.2.5 Windows 8.1 Intellij IDEA 14.0.2

有人可以解释为什么配置文件属性不起作用吗?还是我做错了什么?提前致谢。

Cra*_*ing 6

Maven属性不是系统属性。

如果需要读取/使用系统属性,则必须在适当的maven插件中明确定义它,例如:

  • maven-surefire 单元测试插件
  • maven-jetty-plugin 用于Jetty servlet容器
  • exec-maven-plugin 使用Maven运行您的应用程序
  • properties-maven-plugin 一般用途