-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(maven): forward parameters through target dependencies #33365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
View your CI Pipeline Execution ↗ for commit f23b890
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this 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)
}
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
b76eb89 to
700ffff
Compare
d541477 to
2c991e7
Compare
2c991e7 to
730d139
Compare
730d139 to
f23b890
Compare
| log.info("CI phase '$phase' depends on previous CI phase: '$previousCiPhase'") | ||
| val dependsOnNode = objectMapper.createObjectNode() | ||
| dependsOnNode.put("target", "$previousCiPhase-ci") | ||
| dependsOnNode.put("params", "forward") |
There was a problem hiding this comment.
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>>() |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.) |
There was a problem hiding this comment.
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..
## 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)
|
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. |
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.ktto transform simple string dependency references into structured dependency objects with explicit parameter forwarding: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".