我想使用不同的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>
groovy代码:baseUrl = System.getProperty("useUrl")
System.getProperty("useUrl")
始终返回&#39; null&#39;。
但是如果我在surefire插件中进行配置:
<systemPropertyVariables>
<baseUrl>${useUrl}</baseUrl>
</systemPropertyVariables>
代码System.getProperty("useUrl")
将完全按照我的预期返回 - 来自有效个人资料(http://url
或http://url2
)的值。
系统信息: Maven 3.2.5 Windows 8.1 Intellij IDEA 14.0.2
有人可以解释为什么个人资料属性不起作用吗?或者我做错了什么? 提前谢谢。
答案 0 :(得分:4)
Maven属性不是系统属性。
如果您需要阅读/使用系统属性,则必须在适当的maven插件中明确定义它,例如:
maven-surefire
单元测试插件maven-jetty-plugin
用于Jetty servlet容器exec-maven-plugin
使用maven运行您的应用程序properties-maven-plugin
用于一般用途