38

LinuxボックスでHudsonビルドを実行する場合は、コマンドラインを使用してシステムプロパティをJava仮想マシンに渡します。2.1.0にアップグレードしてから、2.0.9では非常にうまく機能していましたが、完全に機能しなくなりました。システムプロパティは、Java仮想マシンに到達することはありません。

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

これは、Maven2.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); 
4

3 に答える 3

54

これはMavenプラグインでもSurefireプラグインでも問題ではないと思います。それ以外の場合、シュアファイアの動作は異なります。SurefireがJVMをフォークすると、親JVMからすべてのシステムプロパティを取得するわけではないようです。

そのため、argLineを使用して、テストに必要なシステムプロパティをすべて渡す必要があります。したがって、これらは両方とも機能するはずです

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

また

mvn2.1 test -DargLine="-Dsystem.test.property=test"
于 2009-05-05T09:14:41.603 に答える
13

私は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>
于 2009-05-15T17:54:10.183 に答える
2

構成ファイルとコマンドライン引数を混同しないように注意してください。構成ファイル(pom.xml)は、すべてのcmd引数をオーバーライドしています。したがって、raizercostinが説明したように、コマンドラインを介してプラグインを渡す場合は、pom.xml内でsurefireプラグインを構成しないでください。

于 2010-07-15T13:03:10.787 に答える