繁体   English   中英

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

[英]Maven. Profile. Properties and System.getProperty()

我想使用不同的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")始终返回'null'。

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

<systemPropertyVariables>
    <baseUrl>${useUrl}</baseUrl>
</systemPropertyVariables>

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

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

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

Maven属性不是系统属性。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM