Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven 2.1.0 not passing on system properties to Java virtual machine

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.

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);  
like image 325
raisercostin Avatar asked May 05 '09 09:05

raisercostin


People also ask

How do I pass system properties in maven?

To provide System Properties to the tests from command line, you just need to configure maven surefire plugin and use -D{systemproperty}={propertyvalue} parameter in commandline. Run Single Test with Maven : $ mvn test -Dtest=MessageUtilTest#msg_add_test -Dmy_message="Hello, Developer!"

Does maven run on JVM?

Yes , Maven starts the JVM and stop after its use. JVM is needed during its run. like if maven build needs lot of memory [like if you do XML processing] then setting the heap memory using MAVEN_OPTS will be helpful.


1 Answers

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" 
like image 99
raisercostin Avatar answered Oct 21 '22 01:10

raisercostin