<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>non-random ramble &#187; maven</title>
	<atom:link href="http://jimbarritt.com/non-random/category/devops/maven/feed/" rel="self" type="application/rss+xml" />
	<link>http://jimbarritt.com/non-random</link>
	<description>adventures in code</description>
	<lastBuildDate>Tue, 20 Sep 2011 13:16:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Passing System Properties and Environment Variables to unit tests in Maven &#8211; Update</title>
		<link>http://jimbarritt.com/non-random/2009/09/15/passing-system-properties-and-environment-variables-to-unit-tests-in-maven-update/</link>
		<comments>http://jimbarritt.com/non-random/2009/09/15/passing-system-properties-and-environment-variables-to-unit-tests-in-maven-update/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 18:53:19 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[build]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[thoughtblog]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/2009/09/15/passing-system-properties-and-environment-variables-to-unit-tests-in-maven-update/</guid>
		<description><![CDATA[Unfortunately there was an bug in my previous post. I had naively assumed that the syntax for environment variables was the same as for system properties but alas not. The correct code is:]]></description>
			<content:encoded><![CDATA[<p>Unfortunately there was an bug in my previous post.</p>
<p>I had naively assumed that the syntax for environment variables was the same as for system properties but alas not.</p>
<p>The correct code is:</p>
<pre name='code' class='xml:nogutter:nocontrols'>
<build>
    <defaultgoal>package</defaultgoal>
        &lt;plugins>
        &lt;plugin>
               <groupid>org.apache.maven.plugins</groupid>
               <artifactid>maven-surefire-plugin</artifactid>
               <version>2.4.2</version>
               <configuration>
                   <environmentvariables>
                       <some_env_variable>some value</some_env_variable>
                   </environmentvariables>
                   <systemproperties>
                       &lt;property>
                           <name>acceptance.test.host</name>
                           <value>${acceptance.test.host}</value>
                       &lt;/property>
                   </systemproperties>
                </configuration>
           &lt;/plugin>
       &lt;/plugins>
</build>
</pre>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2009%2F09%2F15%2Fpassing-system-properties-and-environment-variables-to-unit-tests-in-maven-update%2F&amp;title=Passing%20System%20Properties%20and%20Environment%20Variables%20to%20unit%20tests%20in%20Maven%20%E2%80%93%20Update" id="wpa2a_2"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2009/09/15/passing-system-properties-and-environment-variables-to-unit-tests-in-maven-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passing System Properties and Environment Variables to unit tests in Maven</title>
		<link>http://jimbarritt.com/non-random/2009/09/15/passing-system-properties-and-environment-variables-to-unit-tests-in-maven/</link>
		<comments>http://jimbarritt.com/non-random/2009/09/15/passing-system-properties-and-environment-variables-to-unit-tests-in-maven/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 16:06:17 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[build]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[thoughtblog]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/2009/09/15/passing-system-properties-and-environment-variables-to-unit-tests-in-maven/</guid>
		<description><![CDATA[This is a bit of dark magic &#8230; &#60;pre&#62; &#60;build&#62; &#60;defaultGoal&#62;package&#60;/defaultGoal&#62; &#60;plugins&#62; &#60;plugin&#62; &#60;groupId&#62;org.apache.maven.plugins&#60;/groupId&#62; &#60;artifactId&#62;maven-surefire-plugin&#60;/artifactId&#62; &#60;version&#62;2.4.2&#60;/version&#62; &#60;configuration&#62; &#60;environmentVariables&#62; &#60;SOME_ENV_VARIABLE&#62;some value&#60;/SOME_ENV_VARIABLE&#62; &#60;/environmentVariables&#62; &#60;systemProperties&#62; &#60;property&#62; &#60;name&#62;someSystemProperty&#60;/name&#62; &#60;value&#62;${thisCanBePassedIn}&#60;/value&#62; &#60;/property&#62; &#60;/systemProperties&#62; &#60;/configuration&#62; &#60;/plugin&#62; &#60;/plugins&#62; &#60;/build&#62; I'm afraid I had to update this post as initially I naively assumed that the syntax for environment variables was the same as for [...]]]></description>
			<content:encoded><![CDATA[<p>This is a bit of dark magic &#8230;</p>
<p>&lt;pre&gt;<br />
 &lt;build&gt;<br />
        &lt;defaultGoal&gt;package&lt;/defaultGoal&gt;<br />
        &lt;plugins&gt;<br />
            &lt;plugin&gt;<br />
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br />
                &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;<br />
                &lt;version&gt;2.4.2&lt;/version&gt;<br />
                &lt;configuration&gt;<br />
                    &lt;environmentVariables&gt;<br />
                        &lt;SOME_ENV_VARIABLE&gt;some value&lt;/SOME_ENV_VARIABLE&gt;<br />
                    &lt;/environmentVariables&gt;<br />
                    &lt;systemProperties&gt;<br />
                        &lt;property&gt;<br />
                            &lt;name&gt;someSystemProperty&lt;/name&gt;<br />
                            &lt;value&gt;${thisCanBePassedIn}&lt;/value&gt;<br />
                        &lt;/property&gt;<br />
                    &lt;/systemProperties&gt;<br />
                 &lt;/configuration&gt;<br />
            &lt;/plugin&gt;<br />
        &lt;/plugins&gt;<br />
    &lt;/build&gt;
</pre>
<p>I'm afraid I had to update this post as initially I naively assumed that the syntax for environment variables was the same as for system properties. As you can see from above, you have to actually put a separate xml tag in there for the variable.</p>
<p>By putting the value in ${} you can then pass it in with <code>-DsomeSystemProperty</code> from the command line when you do <code>mvn clean install</code></p>
<p>e.g. :</p>
<pre>
mvn -DsomeSystemProperty=foobar clean install
</pre>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2009%2F09%2F15%2Fpassing-system-properties-and-environment-variables-to-unit-tests-in-maven%2F&amp;title=Passing%20System%20Properties%20and%20Environment%20Variables%20to%20unit%20tests%20in%20Maven" id="wpa2a_4"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2009/09/15/passing-system-properties-and-environment-variables-to-unit-tests-in-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

