diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8340GeneratedPomInTargetTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8340GeneratedPomInTargetTest.java
new file mode 100644
index 000000000..c121e583b
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8340GeneratedPomInTargetTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+package org.apache.maven.it;
+
+import java.io.File;
+
+import org.apache.maven.shared.verifier.Verifier;
+import org.apache.maven.shared.verifier.util.ResourceExtractor;
+import org.junit.jupiter.api.Test;
+
+/**
+ * This is a test set for MNG-8340.
+ */
+class MavenITmng8340GeneratedPomInTargetTest extends AbstractMavenIntegrationTestCase {
+
+ MavenITmng8340GeneratedPomInTargetTest() {
+ super("[3.8.6,)");
+ }
+
+ /**
+ * Verify that the build succeeds.
+ */
+ @Test
+ void testProjectWithShadePluginAndGeneratedPomUnderTarget() throws Exception {
+ File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8340");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ verifier.addCliArgument("package");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+ }
+}
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
index e864606d7..4bf5b649e 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
@@ -120,6 +120,7 @@ public TestSuiteOrdering() {
* the tests are to finishing. Newer tests are also more likely to fail, so this is
* a fail fast technique as well.
*/
+ suite.addTestSuite(MavenITmng8340GeneratedPomInTargetTest.class);
suite.addTestSuite(MavenITmng8360SubprojectProfileActivationTest.class);
suite.addTestSuite(MavenITmng8347TransitiveDependencyManagerTest.class);
suite.addTestSuite(MavenITmng8341DeadlockTest.class);
diff --git a/core-it-suite/src/test/resources/mng-8340/child1/pom.xml b/core-it-suite/src/test/resources/mng-8340/child1/pom.xml
new file mode 100644
index 000000000..be68873dd
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-8340/child1/pom.xml
@@ -0,0 +1,42 @@
+
+
+
+ 4.0.0
+
+ org.apache.maven.it.mng8340
+ root
+ 1.0.0
+
+
+ child1
+
+
+
+ org.slf4j
+ slf4j-api
+ 2.0.16
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.5.0
+
+
+ shade
+
+ shade
+
+ package
+
+ ${basedir}/target/dr-pom.xml
+
+
+
+
+
+
+
diff --git a/core-it-suite/src/test/resources/mng-8340/child2/pom.xml b/core-it-suite/src/test/resources/mng-8340/child2/pom.xml
new file mode 100644
index 000000000..defeefc3c
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-8340/child2/pom.xml
@@ -0,0 +1,21 @@
+
+
+
+ 4.0.0
+
+ org.apache.maven.it.mng8340
+ root
+ 1.0.0
+
+
+ child2
+
+
+
+ org.apache.maven.it.mng8340
+ child1
+ ${project.version}
+
+
+
+
diff --git a/core-it-suite/src/test/resources/mng-8340/pom.xml b/core-it-suite/src/test/resources/mng-8340/pom.xml
new file mode 100644
index 000000000..2a04859db
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-8340/pom.xml
@@ -0,0 +1,15 @@
+
+
+
+ 4.0.0
+
+ org.apache.maven.it.mng8340
+ root
+ 1.0.0
+ pom
+
+
+ child1
+ child2
+
+