Skip to content

Commit 6b7b8c4

Browse files
committed
feat(maven): improve invoker configuration with pom file and repo settings
1 parent 2afb320 commit 6b7b8c4

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

mise.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[tools]
22
dotnet = "9"
33
java = "24"
4+
maven = "latest"
45
node = "24"
56
rust = "1.90.0"

packages/maven/batch-runner/src/main/kotlin/dev/nx/maven/runner/MavenInvokerRunner.kt

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dev.nx.maven.runner
33
import dev.nx.maven.data.MavenBatchOptions
44
import dev.nx.maven.data.MavenBatchTask
55
import dev.nx.maven.data.TaskResult
6+
import dev.nx.maven.data.Task
67
import dev.nx.maven.utils.MavenCommandResolver
78
import org.apache.maven.shared.invoker.DefaultInvoker
89
import 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

Comments
 (0)