From b63f5df76cccb32ac65d2ae6f73ba9bd76af350c Mon Sep 17 00:00:00 2001
From: Cheryl King <cheryllk@us.ibm.com>
Date: Mon, 2 Oct 2023 13:31:31 -0500
Subject: [PATCH] Fix for multimod restart server problem

---
 .../tools/maven/server/StartDebugMojoSupport.java      | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java
index c8fdce107..c8a0a21a5 100644
--- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java
+++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java
@@ -288,9 +288,13 @@ protected Plugin getLibertyPluginForProject(MavenProject currentProject) {
         }
         Plugin projectPlugin = currentProject.getPlugin(LIBERTY_MAVEN_PLUGIN_GROUP_ID + ":" + LIBERTY_MAVEN_PLUGIN_ARTIFACT_ID);
         if (projectPlugin == null) {
+            getLog().debug("Did not find liberty-maven-plugin configured in currentProject: "+currentProject.toString());
             projectPlugin = getPluginFromPluginManagement(LIBERTY_MAVEN_PLUGIN_GROUP_ID, LIBERTY_MAVEN_PLUGIN_ARTIFACT_ID, currentProject);
+        } else {
+            getLog().debug("Found liberty-maven-plugin configured in currentProject: "+currentProject.toString());
         }
         if (projectPlugin == null) {
+            getLog().debug("Did not find liberty-maven-plugin in pluginManagement in currentProject: "+currentProject.toString());
             projectPlugin = plugin(LIBERTY_MAVEN_PLUGIN_GROUP_ID, LIBERTY_MAVEN_PLUGIN_ARTIFACT_ID, "LATEST");
         }
         if (version != null) {
@@ -370,8 +374,10 @@ protected void runLibertyMojoGenerateFeatures(Element classFiles, boolean optimi
     private void runLibertyMojo(String goal, Xpp3Dom config) throws MojoExecutionException {
         getLog().info("Running liberty:" + goal);
         getLog().debug("configuration:\n" + config);
-        executeMojo(getLibertyPlugin(), goal(goal), config,
-                executionEnvironment(project, session, pluginManager));
+        getLog().debug("project:\n" + project);
+        MavenSession tempSession = session.clone();
+        tempSession.setCurrentProject(project);
+        executeMojo(getLibertyPlugin(), goal(goal), config, executionEnvironment(project, tempSession, pluginManager));
     }
 
     private void copyDependencies() throws MojoExecutionException, IOException {