fix(gradle): tee batch runner output to stderr for terminal display#34630
fix(gradle): tee batch runner output to stderr for terminal display#34630FrozenPandaz merged 2 commits intomasterfrom
Conversation
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
View your CI Pipeline Execution ↗ for commit e0f2ca1
☁️ Nx Cloud last updated this comment at |
Gradle batch output was captured into ByteArrayOutputStream but never forwarded to the terminal. Add TeeOutputStream to write Gradle stdout and stderr to both the capture buffer and System.err, so output flows through the batch worker's stderr pipe to the terminal in real-time. Also replace PseudoTerminal (which swallowed output with quiet mode) with execSync using inherited stderr for direct pipe passthrough.
341e0e3 to
9ba85d5
Compare
There was a problem hiding this comment.
✅ The fix from Nx Cloud was applied
The ktfmt formatting check was failing because the newly added TeeOutputStream.kt file didn't comply with the project's Kotlin formatting standards. We fixed this by running ./gradlew :gradle-batch-runner:ktfmtFormat, which reformatted the KDoc comment and class declaration to match ktfmt conventions. This resolves the :gradle-batch-runner:gradle:ktfmtCheckMain task failure.
Tip
✅ We verified this fix by re-running :gradle-batch-runner:gradle:ktfmtCheckMain.
Suggested Fix changes
diff --git a/packages/gradle/batch-runner/src/main/kotlin/dev/nx/gradle/runner/TeeOutputStream.kt b/packages/gradle/batch-runner/src/main/kotlin/dev/nx/gradle/runner/TeeOutputStream.kt
index 9eb9c05a61..8e31b895a2 100644
--- a/packages/gradle/batch-runner/src/main/kotlin/dev/nx/gradle/runner/TeeOutputStream.kt
+++ b/packages/gradle/batch-runner/src/main/kotlin/dev/nx/gradle/runner/TeeOutputStream.kt
@@ -3,14 +3,11 @@ package dev.nx.gradle.runner
import java.io.OutputStream
/**
- * An OutputStream that writes to two destinations simultaneously.
- * Used to capture Gradle output for JSON results while also
- * forwarding it to stderr for real-time terminal display.
+ * An OutputStream that writes to two destinations simultaneously. Used to capture Gradle output for
+ * JSON results while also forwarding it to stderr for real-time terminal display.
*/
-class TeeOutputStream(
- private val primary: OutputStream,
- private val secondary: OutputStream
-) : OutputStream() {
+class TeeOutputStream(private val primary: OutputStream, private val secondary: OutputStream) :
+ OutputStream() {
override fun write(b: Int) {
primary.write(b)
🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.
View interactive diff ↗➡️ This fix was applied by Jason Jean
🎓 Learn more about Self-Healing CI on nx.dev
Co-authored-by: FrozenPandaz <[email protected]>
🐳 We have a release for that!This PR has a release associated with it. You can try it out using this command: npx [email protected] my-workspaceOr just copy this version and use it in your own command: 22.6.0-pr.34630.341e0e3
To request a new release for this pull request, mention someone from the Nx team or the |
…34630) ## Current Behavior When running Gradle batch tasks (e.g. `nx build my-gradle-project --no-tui`), the terminal shows no task output. The Gradle build output is captured into `ByteArrayOutputStream` for JSON results but never forwarded to the terminal. Users can only see the output in Nx Cloud task results. ## Expected Behavior Gradle batch task output (build logs, test results, etc.) should be visible in the terminal in real-time as the batch executes. ## Changes - **`TeeOutputStream.kt`** (new): An `OutputStream` that writes to two destinations simultaneously — captures output for JSON results while also forwarding to `System.err` for terminal display. - **`GradleRunner.kt`**: Wrap `setStandardOutput` and `setStandardError` with `TeeOutputStream` to tee into `System.err` in both `runBuildLauncher` and `runTestLauncher`. - **`gradle-batch.impl.ts`**: Replace `PseudoTerminal` (which swallowed all output with `quiet: true`) with `execSync` using `stdio: ['pipe', 'pipe', 'inherit']` so stderr flows directly to the terminal. --------- Co-authored-by: nx-cloud[bot] <71083854+nx-cloud[bot]@users.noreply.github.com> Co-authored-by: FrozenPandaz <[email protected]> (cherry picked from commit 923fc45)
|
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
When running Gradle batch tasks (e.g.
nx build my-gradle-project --no-tui), the terminal shows no task output. The Gradle build output is captured intoByteArrayOutputStreamfor JSON results but never forwarded to the terminal. Users can only see the output in Nx Cloud task results.Expected Behavior
Gradle batch task output (build logs, test results, etc.) should be visible in the terminal in real-time as the batch executes.
Changes
TeeOutputStream.kt(new): AnOutputStreamthat writes to two destinations simultaneously — captures output for JSON results while also forwarding toSystem.errfor terminal display.GradleRunner.kt: WrapsetStandardOutputandsetStandardErrorwithTeeOutputStreamto tee intoSystem.errin bothrunBuildLauncherandrunTestLauncher.gradle-batch.impl.ts: ReplacePseudoTerminal(which swallowed all output withquiet: true) withexecSyncusingstdio: ['pipe', 'pipe', 'inherit']so stderr flows directly to the terminal.