Skip to content

Conversation

@FrozenPandaz
Copy link
Collaborator

Current Behavior

Maven target dependencies are defined as simple strings that reference other targets. Currently, parameters are not forwarded through these dependencies when Maven goals are executed.

Expected Behavior

Target dependencies in Maven should forward parameters (args) to their dependency targets, enabling better parameter propagation through the build pipeline.

Changes Made

Modified NxTargetFactory.kt to transform simple string dependency references into structured dependency objects with explicit parameter forwarding:

  • Install dependencies now forward parameters
  • Phase dependencies now forward parameters
  • Test dependencies now forward parameters
  • CI target dependencies now forward parameters

This ensures that when a Maven goal executes, any parameters passed to it are properly forwarded to all transitive target dependencies.

Related Issue(s)

This change enables parameter passing through Maven target dependencies via the new dependency object format with "params": "forward".

@netlify
Copy link

netlify bot commented Nov 4, 2025

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit f23b890
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/690a593fbb989e0008bd9214
😎 Deploy Preview https://deploy-preview-33365--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@vercel
Copy link

vercel bot commented Nov 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Nov 4, 2025 7:59pm

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Nov 4, 2025

View your CI Pipeline Execution ↗ for commit f23b890

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 5m 4s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 1m 7s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 9s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗
nx-cloud record -- nx format:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2025-11-04 20:00:33 UTC

Copy link
Contributor

@nx-cloud nx-cloud bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nx Cloud is proposing a fix for your failed CI:

These changes fix the test failure by correcting the object format for target dependencies. The PR incorrectly used {"target": "^install"} which is invalid in Nx—the ^ prefix only works in string shorthand format. We've updated the code to use {"dependencies": true, "target": "install"} which properly runs the target on all project dependencies while forwarding parameters.

We verified this fix by re-running e2e-maven:e2e-ci--src/maven.test.ts.

Suggested Fix changes
diff --git a/packages/maven/maven-plugin/src/main/kotlin/dev/nx/maven/targets/NxTargetFactory.kt b/packages/maven/maven-plugin/src/main/kotlin/dev/nx/maven/targets/NxTargetFactory.kt
index 96e0133f0f..0cccb9405d 100644
--- a/packages/maven/maven-plugin/src/main/kotlin/dev/nx/maven/targets/NxTargetFactory.kt
+++ b/packages/maven/maven-plugin/src/main/kotlin/dev/nx/maven/targets/NxTargetFactory.kt
@@ -297,7 +297,8 @@ class NxTargetFactory(
 
     if (hasInstall) {
       val dependsOnNode = objectMapper.createObjectNode()
-      dependsOnNode.put("target", "^install")
+      dependsOnNode.put("dependencies", true)
+      dependsOnNode.put("target", "install")
       dependsOnNode.put("params", "forward")
       target.dependsOn?.add(dependsOnNode)
       phaseDependsOn[phase]?.add("^install")
@@ -371,7 +372,14 @@ class NxTargetFactory(
     // Add phase dependencies to all CI targets
     ciPhaseDependsOn.forEach {
       val dependsOnNode = objectMapper.createObjectNode()
-      dependsOnNode.put("target", it)
+      if (it.startsWith("^")) {
+        // For dependencies (^ prefix), use dependencies: true and target without prefix
+        dependsOnNode.put("dependencies", true)
+        dependsOnNode.put("target", it.substring(1))
+      } else {
+        // For same-project dependencies, just use target
+        dependsOnNode.put("target", it)
+      }
       dependsOnNode.put("params", "forward")
       ciTarget.dependsOn?.add(dependsOnNode)
     }
@@ -603,7 +611,14 @@ class NxTargetFactory(
       val dependsOn = objectMapper.createArrayNode()
       testDependsOn.forEach {
         val dependsOnNode = objectMapper.createObjectNode()
-        dependsOnNode.put("target", it)
+        if (it.startsWith("^")) {
+          // For dependencies (^ prefix), use dependencies: true and target without prefix
+          dependsOnNode.put("dependencies", true)
+          dependsOnNode.put("target", it.substring(1))
+        } else {
+          // For same-project dependencies, just use target
+          dependsOnNode.put("target", it)
+        }
         dependsOnNode.put("params", "forward")
         dependsOn.add(dependsOnNode)
       }

Apply fix via Nx Cloud  Reject fix via Nx Cloud

Or Apply changes locally with:

npx nx-cloud apply-locally ROtX-TXRc

Apply fix locally with your editor ↗   View interactive diff ↗


🎓 To learn more about Self Healing CI, please visit nx.dev

@FrozenPandaz FrozenPandaz changed the title feat(maven): forward parameters through target dependencies fix(maven): forward parameters through target dependencies Nov 4, 2025
@FrozenPandaz FrozenPandaz force-pushed the pass-args branch 2 times, most recently from d541477 to 2c991e7 Compare November 4, 2025 19:07
log.info("CI phase '$phase' depends on previous CI phase: '$previousCiPhase'")
val dependsOnNode = objectMapper.createObjectNode()
dependsOnNode.put("target", "$previousCiPhase-ci")
dependsOnNode.put("params", "forward")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main kind of change in this PR.

val nxTargets = objectMapper.createObjectNode()
val targetGroups = mutableMapOf<String, List<String>>()

val phaseDependsOn = mutableMapOf<String, MutableList<String>>()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stopped passing this around... the test-ci phase is the only one that is needed. Now it grabs it out of nxTargets directly.

val goalSpec = if (execution != null) "$goalPrefix:$goalName@${execution.id}" else "$goalPrefix:$goalName"
val command =
"$mavenCommand $goalSpec -pl ${project.groupId}:${project.artifactId} $nonRecursiveFlag --batch-mode".replace(
"$mavenCommand $goalSpec -pl ${project.groupId}:${project.artifactId} $nonRecursiveFlag".replace(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--batch-mode wasn't needed.

if (trimmed.contains("public class ")) {
// Simple extraction: find "public class ClassName"
if (trimmed.contains("class ")) {
// Simple extraction: find "class ClassName" (handles public, package-private, etc.)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test classes don't have to be public? At least the ones generated for Spring do not..

@FrozenPandaz FrozenPandaz merged commit 6144211 into master Nov 6, 2025
20 checks passed
@FrozenPandaz FrozenPandaz deleted the pass-args branch November 6, 2025 16:56
FrozenPandaz added a commit that referenced this pull request Nov 10, 2025
## Current Behavior

Maven target dependencies are defined as simple strings that reference
other targets. Currently, parameters are not forwarded through these
dependencies when Maven goals are executed.

## Expected Behavior

Target dependencies in Maven should forward parameters (args) to their
dependency targets, enabling better parameter propagation through the
build pipeline.

## Changes Made

Modified `NxTargetFactory.kt` to transform simple string dependency
references into structured dependency objects with explicit parameter
forwarding:

- Install dependencies now forward parameters
- Phase dependencies now forward parameters
- Test dependencies now forward parameters
- CI target dependencies now forward parameters

This ensures that when a Maven goal executes, any parameters passed to
it are properly forwarded to all transitive target dependencies.

## Related Issue(s)

This change enables parameter passing through Maven target dependencies
via the new dependency object format with `"params": "forward"`.

(cherry picked from commit 6144211)
@github-actions
Copy link
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants