@@ -3,6 +3,7 @@ package dev.nx.maven.runner
33import dev.nx.maven.data.MavenBatchOptions
44import dev.nx.maven.data.MavenBatchTask
55import dev.nx.maven.data.TaskResult
6+ import dev.nx.maven.data.Task
67import dev.nx.maven.utils.MavenCommandResolver
78import org.apache.maven.shared.invoker.DefaultInvoker
89import org.apache.maven.shared.invoker.DefaultInvocationRequest
@@ -157,11 +158,31 @@ class MavenInvokerRunner(private val options: MavenBatchOptions) {
157158 val request = DefaultInvocationRequest ()
158159 request.baseDirectory = File (options.workspaceRoot)
159160
160- // Don't filter by project selector (-pl flag)
161- // Maven will discover and build all modules in the reactor
162- // The Nx goals will handle recording execution for the specific project
161+ // Set the pom file explicitly
162+ val pomFile = File (options.workspaceRoot, " pom.xml" )
163+ if (pomFile.exists()) {
164+ request.pomFile = pomFile
165+ log.info(" Using pom file: ${pomFile.absolutePath} " )
166+ }
163167
164- request.projects = mutableListOf (project)
168+ // Get the actual project from task graph and use projectRoot as module selector
169+ val task = options.taskGraph?.tasks?.values?.find { it.target.project == project }
170+ if (task != null ) {
171+ log.info(" DEBUG: Found task for project '$project '" )
172+ log.info(" DEBUG: task.target.project = '${task.target.project} '" )
173+ log.info(" DEBUG: task.projectRoot = '${task.projectRoot} '" )
174+
175+ // Use projectRoot if available, otherwise fall back to target.project
176+ if (task.projectRoot != null ) {
177+ request.projects = mutableListOf (task.projectRoot)
178+ log.info(" Using projectRoot as selector: ${task.projectRoot} " )
179+ } else {
180+ request.projects = mutableListOf (task.target.project)
181+ log.info(" Using target.project as selector: ${task.target.project} " )
182+ }
183+ } else {
184+ log.warn(" Could not find task for project '$project ' in task graph" )
185+ }
165186
166187 request.goals = mutableListOf ()
167188 // Collect all goals from tasks (with Nx wrapper goals)
@@ -222,6 +243,15 @@ class MavenInvokerRunner(private val options: MavenBatchOptions) {
222243 log.warn(" Maven home not found, using system Maven" )
223244 }
224245
246+ // Set local repository directory
247+ val localRepoPath = System .getenv(" M2_HOME" )?.let { File (it, " repository" ) }
248+ ? : File (System .getProperty(" user.home" ), " .m2/repository" )
249+
250+ if (localRepoPath.exists() || localRepoPath.parentFile?.exists() == true ) {
251+ invoker.localRepositoryDirectory = localRepoPath
252+ log.info(" Using local repository: ${localRepoPath.absolutePath} " )
253+ }
254+
225255 return invoker
226256 }
227257
0 commit comments