views:

3523

answers:

5

We use the command line to pass on system properties to the Java virtual machine when running our Hudson builds on a Linux box. It used to work quite well in 2.0.9 by since we upgraded to 2.1.0 it has stopped working altogether. The system properties just never make it to the Java virtual machine.

I have created a small test project and indeed it does not work at all. I have attached it in case you want to give it a go.

This should work just fine with Maven 2.0.9:

mvn2.0.9 -Dsystem.test.property=test test 

But this will fail:

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

The Java code simply does this

assertTrue( System.getProperty("system.test.property") != null); 

, Apr 20, 2009; 12:44pm edward eric pedersson

+5  A: 

I don't think this is a problem in either Maven or Surefire plug-in. Else the surefire is behaving differently. It looks like now, when Surefire forks the JVM, will not take all the system properties from the parent JVM.

That's why you should pass whatever system properties you want for the tests, using argLine. So, both these should work

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

or

mvn2.1 test -DargLine="-Dsystem.test.property=test"
raisercostin
"argLine" was just what I was looking for! Many thanks!
armandino
+2  A: 

I've experienced this with the Surefire plug-in. The Surefire plug-in is run under a different JVM instance that is launched by Maven. The command line params are configurable under the surefile-plugin configuration in your pom.xml. Here is a sample of our configuration.

        <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>
Mike Pone
Nowadays use <systemPropertyVariables> instead of <systemProperties>. See http://maven.apache.org/plugins/maven-surefire-plugin/examples/system-properties.html
Willie Wheeler
A: 

A HUGE thanks! this solved the very same issue I was having. I created a Selenium RC test that I wanted to run via Hudson. I wanted the steer the Selenium RC test to go to either *iexplore or *Firefox3. I am now running the following in my Hudson project's configuration page

clean integration-test -DseleniumServer.browser=*iexplore -DforkMode=never

and my integration test is now working!

Donny Thanks
A: 

None of the proposed solutions work on our server. We have

        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.4.3</version>
        <configuration>
            <skip>false</skip>

            <systemPropertyVariables>
                <selenium-server>192.168.192.253</selenium-server>
                <selenium-port>4444</selenium-port>
                <selenium-browser>*firefox</selenium-browser>
            </systemPropertyVariables>

        </configuration>
    </plugin>

I've also tried manually setting values via Hudson configuration like this:

clean install -Dselenium-server=192.168.192.253 -DforkMode=never

No avail.

Surefire lists injected system properties, but they never appear to the test code while executing. Any ideas?

<testsuite failures="0" time="0.027" errors="1" skipped="0" tests="1" name="fi.finnpos.hos.ui.web.LoginTest">  <properties>
<property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
<property name="sun.boot.library.path" value="/usr/lib/java/lib/i386"/>
<property name="java.vm.version" value="10.0-b22"/>
<property name="selenium-server" value="192.168.192.253"/>
<!-- . . .  -->

Paavo Toivanen
Use the version 2.5 of the plugin.
Pascal Thivent
@Pascal Thivent: Thank you for advice. Actually worked for me: after switching from 2.4.3 to 2.5 `<systemPropertyVariables>` started to work magically. I failed to find anything relevant in JIRA.
dma_k
A: 

Be careful to not mix up configuration file with command line arguments. Configuration file (pom.xml) is overriding all the cmd arguments. So don't configure surefire plugin within pom.xml if you want to pass it throught command line like raisercostin explained.

bogdandrags