rai*_*tin 38 maven-2 jvm system-properties maven-plugin surefire
在Linux 机器上运行Hudson构建时,我们使用命令行将系统属性传递给Java虚拟机.它曾经在2.0.9中很好地工作,因为我们升级到2.1.0它已经完全停止工作.系统属性永远不会进入Java虚拟机.
我创建了一个小型测试项目,实际上根本不起作用.
这应该适用于Maven 2.0.9:
mvn2.0.9 -Dsystem.test.property=test test
Run Code Online (Sandbox Code Playgroud)
但这会失败:
mvn2.1 -Dsystem.test.property=test test
Run Code Online (Sandbox Code Playgroud)
Java代码就是这么做的
assertTrue( System.getProperty("system.test.property") != null);
Run Code Online (Sandbox Code Playgroud)
rai*_*tin 53
我不认为这是Maven或Surefire插件中的问题.否则,万不得已表现出不同的表现.现在看来,当Surefire分叉JVM时,不会从父JVM获取所有系统属性.
这就是为什么你应该使用argLine传递你想要的任何系统属性进行测试.所以,这两个都应该有效
mvn2.1 -Dsystem.test.property=test test -DforkMode=never
Run Code Online (Sandbox Code Playgroud)
要么
mvn2.1 test -DargLine="-Dsystem.test.property=test"
Run Code Online (Sandbox Code Playgroud)
Mik*_*one 12
我通过Surefire插件体验过这一点.Surefire插件在Maven启动的不同JVM实例下运行.命令行参数可以在pom.xml中的surefile-plugin配置下配置.以下是我们配置的示例.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<!--
By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:
"**/Test*.java" - includes all of its subdirectory and all java filenames that start with "Test". "**/*Test.java" -
includes all of its subdirectory and all java filenames that end with "Test". "**/*TestCase.java" - includes all of
its subdirectory and all java filenames that end with "TestCase".
-->
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
<systemProperties>
<property>
<name>app.env</name>
<value>dev</value>
</property>
<property>
<name>oracle.net.tns_admin</name>
<value>${oracle.net.tns_admin}</value>
</property>
</systemProperties>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)