Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/devkit/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export {
createProjectRootMappingsFromProjectConfigurations,
PluginCache,
safeWriteFileCache,
emitPluginWorkerLog,
} from 'nx/src/devkit-internals';

// Generators
Expand Down
22 changes: 22 additions & 0 deletions packages/gradle/plugin-v1.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
import { emitPluginWorkerLog } from '@nx/devkit/internal';

// TODO(v24): remove `@nx/gradle/plugin-v1` entirely. Users should be migrated
// to `@nx/gradle` (the atomized v2 plugin) via the removal migration shipped
// alongside the deletion.
//
// Use emitPluginWorkerLog so the warning surfaces to the user even when the
// daemon is enabled — `logger.warn` would route to the daemon log file and
// be silently swallowed. Guard against older nx versions (< 22.7) where this
// helper may not exist; @nx/devkit supports nx at +/-1 major.
if (typeof emitPluginWorkerLog === 'function') {
emitPluginWorkerLog(
'warn',
'`@nx/gradle/plugin-v1` is deprecated and will be removed in Nx 24. ' +
'Switch your `nx.json` plugins entry from `@nx/gradle/plugin-v1` to `@nx/gradle`. ' +
'Note that the default `@nx/gradle` plugin generates atomized targets — ' +
'see https://nx.dev/nx-api/gradle for configuration options.'
);
}
Comment on lines +11 to +19
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The typeof guard will not protect against older Nx versions lacking emitPluginWorkerLog. If the export doesn't exist in @nx/devkit/internal, the import statement at line 1 will throw a module resolution error before reaching the type check. This breaks the stated goal of supporting "@nx/devkit supports nx at +/-1 major" for Nx < 22.7.

Fix: Use dynamic import with try-catch:

try {
  const { emitPluginWorkerLog } = await import('@nx/devkit/internal');
  if (typeof emitPluginWorkerLog === 'function') {
    emitPluginWorkerLog('warn', '...');
  }
} catch {
  // Gracefully degrade on older Nx versions
}

Or conditionally import only when needed and handle the error.

Suggested change
if (typeof emitPluginWorkerLog === 'function') {
emitPluginWorkerLog(
'warn',
'`@nx/gradle/plugin-v1` is deprecated and will be removed in Nx 24. ' +
'Switch your `nx.json` plugins entry from `@nx/gradle/plugin-v1` to `@nx/gradle`. ' +
'Note that the default `@nx/gradle` plugin generates atomized targets — ' +
'see https://nx.dev/nx-api/gradle for configuration options.'
);
}
try {
const { emitPluginWorkerLog } = await import('@nx/devkit/internal');
if (typeof emitPluginWorkerLog === 'function') {
emitPluginWorkerLog(
'warn',
'`@nx/gradle/plugin-v1` is deprecated and will be removed in Nx 24. ' +
'Switch your `nx.json` plugins entry from `@nx/gradle/plugin-v1` to `@nx/gradle`. ' +
'Note that the default `@nx/gradle` plugin generates atomized targets — ' +
'see https://nx.dev/nx-api/gradle for configuration options.'
);
}
} catch {
// Gracefully degrade on older Nx versions that lack emitPluginWorkerLog
}

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.


/** @deprecated Use `@nx/gradle` instead. This entry will be removed in Nx 24. */
export { createDependencies } from './src/plugin-v1/dependencies';
/** @deprecated Use `@nx/gradle` instead. This entry will be removed in Nx 24. */
export { createNodes, createNodesV2 } from './src/plugin-v1/nodes';
4 changes: 4 additions & 0 deletions packages/gradle/src/plugin-v1/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { basename, dirname } from 'node:path';
import { getCurrentGradleReport } from './utils/get-gradle-report';
import { GRADLE_BUILD_FILES } from '../utils/split-config-files';

/**
* @deprecated The `@nx/gradle/plugin-v1` entry is deprecated and will be removed in Nx 24.
* Switch to the default `@nx/gradle` plugin.
*/
export const createDependencies: CreateDependencies = async (
_,
context: CreateDependenciesContext
Expand Down
4 changes: 4 additions & 0 deletions packages/gradle/src/plugin-v1/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ function normalizeOptions(options: GradlePluginOptions): GradlePluginOptions {

type GradleTargets = Record<string, Partial<ProjectConfiguration>>;

/**
* @deprecated The `@nx/gradle/plugin-v1` entry is deprecated and will be removed in Nx 24.
* Switch to the default `@nx/gradle` plugin.
*/
export const createNodesV2: CreateNodesV2<GradlePluginOptions> = [
gradleConfigAndTestGlob,
async (files, options, context) => {
Expand Down
1 change: 1 addition & 0 deletions packages/nx/src/devkit-internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ export { globalSpinner } from './utils/spinner';
export { signalToCode } from './utils/exit-codes';
export { handleImport } from './utils/handle-import';
export { PluginCache, safeWriteFileCache } from './utils/plugin-cache-utils';
export { emitPluginWorkerLog } from './project-graph/plugins/isolation/worker-streaming';
Loading