Is it possible to set env vars in pom.xml that junit tests uses? Netbeans can get env vars and builds project correnctly. But when i use command line (mvn clean -> mvn install), build fails due to test errors.
Thanks.
Step 5 - Set Maven Environment VariablesAdd M2_HOME, M2, MAVEN_OPTS to environment variables. Set the environment variables using system properties. Open command terminal and set environment variables. Open command terminal and set environment variables.
We can run our unit tests with Maven by using the command: mvn clean test. When we run this command at command prompt, we should see that the Maven Surefire Plugin runs our unit tests. We can now create a Maven project that compiles and runs unit tests which use JUnit 5.
To refer to environment variables from the pom. xml, we can use the ${env. VARIABLE_NAME} syntax. We should remember to pass the Java version information via environment variables.
There are two approaches I know.
Commandline:
You can pass it in command line like
mvn -DAM_HOME=conf install
Using pom :
If AM_HOM
is the variable and the value is conf
,make entry like below.
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
...
<configuration>
...
<environmentVariables>
<AM_HOME>conf</AM_HOME>
</environmentVariables>
</configuration>
</plugin>
...
<plugins>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With