2009-05-05 5 views
38

LinuxマシンでHudsonビルドを実行するときに、コマンドラインを使用してJava 仮想マシンにシステムプロパティを渡します。 が2.1.9にアップグレードして以来、2.09ではかなりうまく動作しました。 が完全に動作を停止しました。システムのプロパティは、Java仮想マシンに対して決してそれを にすることはありません。Maven 2.1.0がJava仮想マシンにシステムプロパティを渡さない

私は小さなテストプロジェクトを作成しましたが、実際には全く機能しません。

これは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); 

答えて

52

をし、私は「ドンこれがMavenまたはSurefireプラグインのいずれかの問題だとは思わない。そうでなければ確信は異なっている。 SurefireがJVMをフォークしたときのように、親JVMからすべてのシステムプロパティを取得することはありません。

そのため、argLineを使用してテストに必要なシステムプロパティを渡す必要があります。 ので、これらの両方が、私はSurefireプラグインでこれを経験した

mvn2.1 -Dsystem.test.property=test test -DforkMode=never 

または

mvn2.1 test -DargLine="-Dsystem.test.property=test" 
+0

"argLine"は私が探していたものでした!どうもありがとう! " - Duser.language =デ-Duser.region = DE" なくMVN試験-DargLine = " - Dsystem.user.language =デLocale.getDefaultための驚くべき – armandino

+0

()これらは MVN試験-DargLine =働い - Dsystem.user.region = DE " – bibstha

+3

あなたは単に' mvn -Dsystem.test.property = test test'を使用していることに注意してください。 Mavenはプロパティをテストに伝播します。 – BetaRide

12

を動作するはずです。 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> 
+4

ではなくを使用します。 http://maven.apache.org/plugins/maven-surefire-plugin/examples/system-properties.html –

+0

これを試してみましたが、$ {...}はプロパティで置き換えられていないようです値はMavenに渡されました... – thecoop

+0

@thecoop - 問題の内容がわからない、どこかにスペルミスがある可能性がありますが、これは私にとってはうまくいっています。 –

2

コンフィギュレーションファイルとコマンドライン引数を混同しないように注意してください。構成ファイル(pom.xml)がすべてのcmd引数をオーバーライドしています。したがって、pom.xml内にsurefireプラグインを設定しないでください。raisercostinのようにコマンドラインを通す必要があります。

関連する問題