Q:

Passing custom environment variables to maven cargo

I'm looking for a way to pass environment variables into a cargo container.  Something like this:
<plugin>
  <groupId>org.codehaus.cargo>
  <artifactId>cargo-maven2-plugin</artifactId>
  <configuration>
    <environmentVariables>
      <myCustomVariable>value</myCustomVariable>
      ...

A:

AFAIK, The cargo only allow to pass the system properties as mentioning at Passing system properties and Maven Tips as the following example: -
<container>
  [...]
  <systemProperties>
    <myproperty>myvalue</myproperty>
  </systemProperties>
</container>

The workaround may be link that system properties to the environment variable as the following example:-
<container>
  [...]
  <systemProperties>
    <myproperty>${env.MY_ENV_VAR}</myproperty>
  </systemProperties>
</container>

Normally we are only able to set the environment variable by using the OS way. Anyhow there also is a workaround for setting it by using Java as mentioning at How do I set environment variables from Java?. 
I always use this tip for setting up the environment variables during unit testing by putting them to the JUnit test suit with @BeforeClass and set them to be empty String with @AfterClass.
Please note that the formal Java Tutorial also mentions about Environment Variables and Passing Environment Variables to New Processes.
I hope this may help.

