#37218·nx

`@nx/gradle`: a version-catalog change invalidates nothing — `nx affected` is empty and cached tasks replay

Author: davidcurrieCreated Sep 28, 2026Updated Sep 28, 2026

Current Behavior

With the configuration @nx/gradle's init generator produces, changing a library version in gradle/libs.versions.toml has no effect on nx at all:

  • nx show projects --affected returns [] for a commit that touches only the catalog
  • cached tasks replay from cache, so a dependency bump serves a stale build

The init generator writes only namedInputs.default ({projectRoot}/**/*) and namedInputs.production. Nothing names the catalog, and @nx/gradle contributes no externalNodes, so nx has no way to connect a catalog edit to the projects that consume the library.

This is not only a caching nicety. With cache: true on the Gradle target defaults, a replay means nx never invokes Gradle, so Gradle's own up-to-date checks never get the chance to notice the changed dependency.

Expected Behavior

Changing an alias should affect, and invalidate, the projects that reference it — the precision npm already has. Measured in a 201-project workspace using real base/head commits:

lockfile commit affected
one workspace link: line 1 of 201
vitest, playwright, webdriverio + 4 others 129 of 201

129 is proportionate rather than coarse: vitest genuinely is a dependency of that many projects. packages/nx/src/plugins/js/project-graph/affected/lock-file-changes.ts parses the lockfile diff, maps changed package names onto externalNodes, and marks only dependents. Gradle has no equivalent.

GitHub Repo

https://github.com/davidcurrie/nx-gradle-affected-repro — see repro B in the README. No JDK or Gradle required.

Steps to Reproduce

bash
git clone https://github.com/davidcurrie/nx-gradle-affected-repro
cd nx-gradle-affected-repro
npm install

npx nx run-many -t noop                 # warm the cache

# bump one library. project-a declares lib-a; project-b declares lib-b.
sed -i '' 's/lib-a-version = "1.0.0"/lib-a-version = "2.0.0"/' gradle/libs.versions.toml
git commit -am "bump lib-a in the catalog"

npx nx show projects --affected --base=HEAD~1 --head=HEAD
npx nx run project-a:noop

Actual:

[]
> nx run project-a:noop  [existing outputs match the cache, left as is]

Expected: ["project-a"], and a cache miss for project-a.

Section B2 of that README runs the same commit range with the catalog named in an input, to show the mitigation and its cost.

The only mitigation, and what it costs

The workaround is to name the catalog in a namedInput used by the Gradle target defaults:

json
"gradleGlobals": ["{workspaceRoot}/gradle/libs.versions.toml", …],
"@nx/gradle:gradle": { "cache": true, "inputs": ["gradleGlobals", …] }

That restores correctness by making every Gradle project depend on the whole catalog. In our monorepo a Renovate commit changing one line — io.fabric8:kubernetes-client, declared by exactly one project — then produced:

projects affected 56 — every project with an @nx/gradle target
package 29
deploy (staging) 29
nx-release-publish 6

So the choice today is between replaying stale builds and redeploying 29 services that did not change. Neither is correct, and nx offers nothing in between.

Why a plugin cannot fix this

The JS half already exists. The report contract declares the field:

typescript
// packages/gradle/src/plugin/utils/get-project-graph-from-gradle-plugin.ts
externalNodes?: Record<string, ProjectGraphExternalNode>;

It is merged when present, and packages/gradle/src/plugin/nodes.ts destructures it from the report and returns it from createNodes. The Gradle-side plugin (dev.nx.gradle.project-graph 0.1.25) never populates it, so the path is inert.

I prototyped the missing half in JS to see whether a plugin could close this without core changes: parse the catalog, map aliases to the projects referencing them, emit externalNodes, and give each project inputs: [{ externalDependencies: [...] }] naming only its own libraries.

Bumping an alias used by exactly one project still left that project replaying from cache. A control confirms the harness — touching that project's own source produced a miss for it and a hit for the unrelated project.

From outside nx I could not distinguish two causes, and both are core-side:

  • externalNodes returned from createNodes do not reach the graph (nx graph --file emits no externalNodes section, so I could not verify directly), or
  • externalDependencies hashing resolves only npm-derived nodes and ignores names it does not recognise.

Suggested fix

Two parts, because the second cannot come from a plugin:

  1. dev.nx.gradle.project-graph emits externalNodes and dependency edges from each project's resolved configurations. Self-contained; the JS consumer already exists.
  2. Core support for resolving them — either make externalDependencies input hashing generic over any plugin's externalNodes, or add a version-catalog locator beside the lockfile one. packages/nx/src/project-graph/affected/affected-project-graph.ts imports the JS locators directly, so a third party cannot contribute one.

Part 1 alone is still worth having: it puts the information in the graph, and part 2 can follow.

Environment

  • nx 23.2.1, @nx/gradle 23.2.1
  • dev.nx.gradle.project-graph 0.1.25
  • pnpm 12.4.2, macOS

Related

  • #36617 — same workspace: deleting any Gradle test file makes nx affected return every project. Different mechanism, same root cause of the Gradle project graph carrying less information than the JS one.