[MSHARED-971] Add test for inherited environment
diff --git a/pom.xml b/pom.xml
index 74b78e9..863f8da 100644
--- a/pom.xml
+++ b/pom.xml
@@ -105,6 +105,9 @@
             <maven.home>${maven.home}</maven.home>
             <maven.repo.local>${settings.localRepository}</maven.repo.local>
           </systemPropertyVariables>
+          <environmentVariables>
+            <INVOKER_TEST_ENV_1>test-env-value</INVOKER_TEST_ENV_1>
+          </environmentVariables>
           <excludes>
             <exclude>test-build-should*/**</exclude>
           </excludes>
diff --git a/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java b/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java
index 6a94b64..8584e56 100644
--- a/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java
+++ b/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java
@@ -29,8 +29,11 @@
 import org.apache.maven.shared.utils.StringUtils;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 class DefaultInvokerTest {
@@ -42,6 +45,7 @@
     public void setUp() {
         request.setDebug(true);
         request.setProperties(getProperties());
+        request.setBatchMode(true);
     }
 
     @Test
@@ -184,6 +188,35 @@
         }
     }
 
+    @Test
+    @DisabledOnOs(OS.WINDOWS) // mvn 3.6.3 and windows ...
+    void notInheritEnvVariables() throws Exception {
+
+        // ensure that we have env variable in current process
+        assertEquals("test-env-value", System.getenv("INVOKER_TEST_ENV_1"));
+
+        File basedir = getBasedirForBuild();
+        request.setBaseDirectory(basedir);
+        request.addArg("initialize");
+        request.setShellEnvironmentInherited(false);
+        request.addShellEnvironment("INVOKER_TEST_ENV_2", "test-env-value-2");
+        // Maven 3.6.3 required JAVA_HOME
+        request.addShellEnvironment("JAVA_HOME", System.getProperty("java.home"));
+
+        final StringBuilder outlines = new StringBuilder();
+        request.setOutputHandler(line -> outlines.append(line).append(System.lineSeparator()));
+
+        InvocationResult result = invoker.execute(request);
+
+        String output = outlines.toString();
+        assertEquals(
+                0,
+                result.getExitCode(),
+                () -> "Maven exit code: " + result.getExitCode() + System.lineSeparator() + output.trim());
+        assertFalse(output.contains("INVOKER_TEST_ENV_1"));
+        assertTrue(output.contains("INVOKER_TEST_ENV_2=test-env-value-2"));
+    }
+
     private Invoker newInvoker() {
         Invoker invoker = new DefaultInvoker();
 
diff --git a/src/test/resources/not-inherit-env-variables/pom.xml b/src/test/resources/not-inherit-env-variables/pom.xml
new file mode 100644
index 0000000..90aee9f
--- /dev/null
+++ b/src/test/resources/not-inherit-env-variables/pom.xml
@@ -0,0 +1,44 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.shared.invoker</groupId>
+  <artifactId>not-inherit-env-variables</artifactId>
+  <packaging>pom</packaging>
+  <version>1</version>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-help-plugin</artifactId>
+        <version>${version.maven-help-plugin}</version>
+        <executions>
+          <execution>
+            <phase>initialize</phase>
+            <goals>
+              <goal>system</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>