Skip to content

fix(gradle): tee batch runner output to stderr for terminal display#34630

Merged
FrozenPandaz merged 2 commits intomasterfrom
fix-gradle-batch
Mar 2, 2026
Merged

fix(gradle): tee batch runner output to stderr for terminal display#34630
FrozenPandaz merged 2 commits intomasterfrom
fix-gradle-batch

Conversation

@FrozenPandaz
Copy link
Copy Markdown
Collaborator

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.

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 26, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit e0f2ca1
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69a0be26214d6e0008608603
😎 Deploy Preview https://deploy-preview-34630--nx-dev.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.

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 26, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit e0f2ca1
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69a0be263347230008157bd6
😎 Deploy Preview https://deploy-preview-34630--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.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud bot commented Feb 26, 2026

View your CI Pipeline Execution ↗ for commit e0f2ca1

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 13m 36s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3m 19s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 7s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-26 21:59:22 UTC

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.
Copy link
Copy Markdown
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.

✅ 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.

Revert fix via Nx Cloud  

View interactive diff ↗

➡️ This fix was applied by Jason Jean

🎓 Learn more about Self-Healing CI on nx.dev

@github-actions
Copy link
Copy Markdown
Contributor

🐳 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-workspace

Or just copy this version and use it in your own command:

22.6.0-pr.34630.341e0e3
Release details 📑
Published version 22.6.0-pr.34630.341e0e3
Triggered by @FrozenPandaz
Branch fix-gradle-batch
Commit 341e0e3
Workflow run 22461752535

To request a new release for this pull request, mention someone from the Nx team or the @nrwl/nx-pipelines-reviewers.

@FrozenPandaz FrozenPandaz merged commit 923fc45 into master Mar 2, 2026
24 checks passed
@FrozenPandaz FrozenPandaz deleted the fix-gradle-batch branch March 2, 2026 18:10
FrozenPandaz added a commit that referenced this pull request Mar 4, 2026
…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)
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 8, 2026

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 Mar 8, 2026
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.

2 participants