Maven 2.1.0 Java Virtual Machine에 시스템 속성을 전달하지 않음
-
05-07-2019 - |
문제
우리는 명령 줄을 사용하여 실행할 때 시스템 속성을 Java 가상 머신에 전달합니다. 허드슨 강 Linux 상자에 빌드합니다. 우리가 2.1.0으로 업그레이드 한 이후로 2.0.9에 상당히 잘 작동했습니다. 시스템 속성은 Java Virtual Machine에 결코 만들지 않습니다.
나는 작은 테스트 프로젝트를 만들었고 실제로는 전혀 작동하지 않습니다.
이것은 잘 작동해야합니다 Maven 2.0.9:
mvn2.0.9 -Dsystem.test.property=test test
그러나 이것은 실패 할 것입니다 :
mvn2.1 -Dsystem.test.property=test test
Java 코드는 단순히 이것을합니다
assertTrue( System.getProperty("system.test.property") != null);
해결책
나는 이것이 Maven 또는 SureFire 플러그인의 문제라고 생각하지 않습니다. 그렇지 않으면 확실한 불이 다르게 행동하고 있습니다. Surefire가 포크 할 때 지금은 보입니다 JVM, 부모 JVM에서 모든 시스템 속성을 가져 가지 않습니다.
그렇기 때문에 Argline을 사용하여 테스트에 원하는 시스템 속성을 전달해야합니다. 따라서 두 가지 모두 작동해야합니다
mvn2.1 -Dsystem.test.property=test test -DforkMode=never
또는
mvn2.1 test -DargLine="-Dsystem.test.property=test"
다른 팁
나는 이것과 함께 이것을 경험했다 확실한 플러그인. 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>
구성 파일을 명령 줄 인수와 혼합하지 않도록주의하십시오. configuration 파일 (pom.xml)이 모든 CMD 인수를 무시하고 있습니다. 따라서 Raisercostin이 설명한 것처럼 명령 줄을 통과하려면 pom.xml 내에서 확실한 플러그인을 구성하지 마십시오.