@nx/gradle 20.2.0-rc.0 → 20.3.0-canary.20241206-cc14411

Sign up to get free protection for your applications and to get access to all the features.
package/migrations.json CHANGED
@@ -11,6 +11,12 @@
11
11
  "cli": "nx",
12
12
  "description": "This function changes !{projectRoot}/test/**/* in nx.json for production to !{projectRoot}/src/test/**/*",
13
13
  "factory": "./src/migrations/19-4-1/change-regex-test-production"
14
+ },
15
+ "add-include-subprojects-tasks": {
16
+ "version": "20.2.0-beta.4",
17
+ "cli": "nx",
18
+ "description": "Add includeSubprojectsTasks to build.gradle file",
19
+ "factory": "./src/migrations/20-2-0/add-include-subprojects-tasks"
14
20
  }
15
21
  },
16
22
  "packageJsonUpdates": {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/gradle",
3
- "version": "20.2.0-rc.0",
3
+ "version": "20.3.0-canary.20241206-cc14411",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Gradle allows Gradle tasks to be run through Nx",
6
6
  "repository": {
@@ -34,7 +34,7 @@
34
34
  "migrations": "./migrations.json"
35
35
  },
36
36
  "dependencies": {
37
- "@nx/devkit": "20.2.0-rc.0"
37
+ "@nx/devkit": "20.3.0-canary.20241206-cc14411"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
@@ -13,7 +13,7 @@ function getCiCommands(ci) {
13
13
  comment: `# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected`,
14
14
  },
15
15
  {
16
- command: `./nx affected --base=$NX_BASE --head=$NX_HEAD -t test build`,
16
+ command: `./nx affected --base=$NX_BASE --head=$NX_HEAD -t build`,
17
17
  },
18
18
  ];
19
19
  }
@@ -22,7 +22,7 @@ function getCiCommands(ci) {
22
22
  {
23
23
  comment: `# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected`,
24
24
  },
25
- { command: `./nx affected -t test build` },
25
+ { command: `./nx affected -t build` },
26
26
  ];
27
27
  }
28
28
  }
@@ -32,6 +32,7 @@ function addPlugin(tree) {
32
32
  testTargetName: 'test',
33
33
  classesTargetName: 'classes',
34
34
  buildTargetName: 'build',
35
+ includeSubprojectsTasks: false,
35
36
  },
36
37
  });
37
38
  (0, devkit_1.updateNxJson)(tree, nxJson);
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): void;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = update;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const has_gradle_plugin_1 = require("../../utils/has-gradle-plugin");
6
+ // This function add options includeSubprojectsTasks as true in nx.json for gradle plugin
7
+ function update(tree) {
8
+ const nxJson = (0, devkit_1.readNxJson)(tree);
9
+ if (!nxJson) {
10
+ return;
11
+ }
12
+ if (!(0, has_gradle_plugin_1.hasGradlePlugin)(tree)) {
13
+ return;
14
+ }
15
+ let gradlePluginIndex = nxJson.plugins.findIndex((p) => typeof p === 'string' ? p === '@nx/gradle' : p.plugin === '@nx/gradle');
16
+ let gradlePlugin = nxJson.plugins[gradlePluginIndex];
17
+ if (typeof gradlePlugin === 'string') {
18
+ gradlePlugin = {
19
+ plugin: '@nx/gradle',
20
+ options: {
21
+ includeSubprojectsTasks: true,
22
+ },
23
+ };
24
+ nxJson.plugins[gradlePluginIndex] = gradlePlugin;
25
+ }
26
+ else {
27
+ gradlePlugin.options ??= {};
28
+ gradlePlugin.options.includeSubprojectsTasks =
29
+ true;
30
+ }
31
+ (0, devkit_1.updateNxJson)(tree, nxJson);
32
+ }
@@ -1,17 +1,14 @@
1
- import { CreateNodes, CreateNodesV2, ProjectConfiguration, TargetConfiguration, CreateNodesFunction } from '@nx/devkit';
1
+ import { CreateNodes, CreateNodesV2, ProjectConfiguration, CreateNodesFunction } from '@nx/devkit';
2
2
  import { GradleReport } from '../utils/get-gradle-report';
3
3
  export interface GradlePluginOptions {
4
+ includeSubprojectsTasks?: boolean;
4
5
  ciTargetName?: string;
5
6
  testTargetName?: string;
6
7
  classesTargetName?: string;
7
8
  buildTargetName?: string;
8
- [taskTargetName: string]: string | undefined;
9
+ [taskTargetName: string]: string | undefined | boolean;
9
10
  }
10
- type GradleTargets = Record<string, {
11
- name: string;
12
- targets: Record<string, TargetConfiguration>;
13
- metadata: ProjectConfiguration['metadata'];
14
- }>;
11
+ type GradleTargets = Record<string, Partial<ProjectConfiguration>>;
15
12
  export declare function writeTargetsToCache(cachePath: string, results: GradleTargets): void;
16
13
  export declare const createNodesV2: CreateNodesV2<GradlePluginOptions>;
17
14
  export declare const makeCreateNodesForGradleConfigFile: (gradleReport: GradleReport, targetsCache?: GradleTargets, gradleProjectRootToTestFilesMap?: Record<string, string[]>) => CreateNodesFunction;
@@ -14,7 +14,7 @@ const split_config_files_1 = require("../utils/split-config-files");
14
14
  const exec_gradle_1 = require("../utils/exec-gradle");
15
15
  const cacheableTaskType = new Set(['Build', 'Verification']);
16
16
  const dependsOnMap = {
17
- build: ['^build', 'classes'],
17
+ build: ['^build', 'classes', 'test'],
18
18
  testClasses: ['classes'],
19
19
  test: ['testClasses'],
20
20
  classes: ['^classes'],
@@ -83,24 +83,36 @@ exports.createNodes = [
83
83
  ];
84
84
  async function createGradleProject(gradleReport, gradleFilePath, options, context, testFiles = []) {
85
85
  try {
86
- const { gradleProjectToTasksTypeMap, gradleFileToOutputDirsMap, gradleFileToGradleProjectMap, gradleProjectToProjectName, } = gradleReport;
86
+ const { gradleProjectToTasksTypeMap, gradleProjectToTasksMap, gradleFileToOutputDirsMap, gradleFileToGradleProjectMap, gradleProjectToProjectName, } = gradleReport;
87
87
  const gradleProject = gradleFileToGradleProjectMap.get(gradleFilePath);
88
88
  const projectName = gradleProjectToProjectName.get(gradleProject);
89
89
  if (!projectName) {
90
90
  return;
91
91
  }
92
92
  const tasksTypeMap = gradleProjectToTasksTypeMap.get(gradleProject);
93
+ const tasksSet = gradleProjectToTasksMap.get(gradleProject);
93
94
  let tasks = [];
94
- for (let [taskName, taskType] of tasksTypeMap.entries()) {
95
+ tasksSet.forEach((taskName) => {
95
96
  tasks.push({
96
- type: taskType,
97
+ type: tasksTypeMap.get(taskName),
97
98
  name: taskName,
98
99
  });
100
+ });
101
+ if (options.includeSubprojectsTasks) {
102
+ tasksTypeMap.forEach((taskType, taskName) => {
103
+ if (!tasksSet.has(taskName)) {
104
+ tasks.push({
105
+ type: taskType,
106
+ name: taskName,
107
+ });
108
+ }
109
+ });
99
110
  }
100
111
  const outputDirs = gradleFileToOutputDirsMap.get(gradleFilePath);
101
112
  const { targets, targetGroups } = await createGradleTargets(tasks, options, context, outputDirs, gradleProject, gradleFilePath, testFiles);
102
113
  const project = {
103
114
  name: projectName,
115
+ projectType: 'application',
104
116
  targets,
105
117
  metadata: {
106
118
  targetGroups,
@@ -151,10 +163,12 @@ async function createGradleTargets(tasks, options, context, outputDirs, gradlePr
151
163
  },
152
164
  ...(outputs && outputs.length ? { outputs } : {}),
153
165
  };
154
- if (!targetGroups[task.type]) {
155
- targetGroups[task.type] = [];
166
+ if (task.type) {
167
+ if (!targetGroups[task.type]) {
168
+ targetGroups[task.type] = [];
169
+ }
170
+ targetGroups[task.type].push(targetName);
156
171
  }
157
- targetGroups[task.type].push(targetName);
158
172
  }
159
173
  return { targetGroups, targets };
160
174
  }
@@ -3,6 +3,7 @@ export interface GradleReport {
3
3
  buildFileToDepsMap: Map<string, string>;
4
4
  gradleFileToOutputDirsMap: Map<string, Map<string, string>>;
5
5
  gradleProjectToTasksTypeMap: Map<string, Map<string, string>>;
6
+ gradleProjectToTasksMap: Map<string, Set<String>>;
6
7
  gradleProjectToProjectName: Map<string, string>;
7
8
  gradleProjectNameToProjectRootMap: Map<string, string>;
8
9
  gradleProjectToChildProjects: Map<string, string[]>;
@@ -61,6 +61,7 @@ function processProjectReports(projectReportLines) {
61
61
  * Map of Gradle Build File to tasks type map
62
62
  */
63
63
  const gradleProjectToTasksTypeMap = new Map();
64
+ const gradleProjectToTasksMap = new Map();
64
65
  const gradleProjectToProjectName = new Map();
65
66
  const gradleProjectNameToProjectRootMap = new Map();
66
67
  /**
@@ -101,6 +102,7 @@ function processProjectReports(projectReportLines) {
101
102
  : [];
102
103
  let projectName, absBuildFilePath, absBuildDirPath;
103
104
  const outputDirMap = new Map();
105
+ const tasks = new Set();
104
106
  for (const line of propertyReportLines) {
105
107
  if (line.startsWith('name: ')) {
106
108
  projectName = line.substring('name: '.length);
@@ -124,6 +126,10 @@ function processProjectReports(projectReportLines) {
124
126
  const taskName = dirName.replace('Dir', '');
125
127
  outputDirMap.set(taskName, `{workspaceRoot}/${(0, node_path_1.relative)(devkit_1.workspaceRoot, dirPath)}`);
126
128
  }
129
+ if (line.includes(': task ')) {
130
+ const [task] = line.split(': task ');
131
+ tasks.add(task);
132
+ }
127
133
  }
128
134
  if (!projectName || !absBuildFilePath || !absBuildDirPath) {
129
135
  continue;
@@ -137,6 +143,7 @@ function processProjectReports(projectReportLines) {
137
143
  gradleFileToGradleProjectMap.set(buildFile, gradleProject);
138
144
  gradleProjectToProjectName.set(gradleProject, projectName);
139
145
  gradleProjectNameToProjectRootMap.set(gradleProject, (0, path_1.dirname)(buildFile));
146
+ gradleProjectToTasksMap.set(gradleProject, tasks);
140
147
  }
141
148
  if (line.endsWith('taskReport')) {
142
149
  const gradleProject = line.substring('> Task '.length, line.length - ':taskReport'.length);
@@ -177,6 +184,7 @@ function processProjectReports(projectReportLines) {
177
184
  buildFileToDepsMap,
178
185
  gradleFileToOutputDirsMap,
179
186
  gradleProjectToTasksTypeMap,
187
+ gradleProjectToTasksMap,
180
188
  gradleProjectToProjectName,
181
189
  gradleProjectNameToProjectRootMap,
182
190
  gradleProjectToChildProjects,
@@ -35,13 +35,13 @@ async function getProjectReportLines(gradlewFile) {
35
35
  projectReportBuffer = await (0, exec_gradle_1.execGradleAsync)(gradlewFile, [
36
36
  'projectReport',
37
37
  ]);
38
- devkit_1.logger.warn(`Could not run 'projectReportAll' task. Ran 'projectReport' instead. Please run 'nx generate @nx/gradle:init' to generate the necessary tasks.`);
38
+ devkit_1.logger.warn(`Could not run 'projectReportAll' task. Ran 'projectReport' instead. Please run 'nx generate @nx/gradle:init' to generate the necessary tasks. ${e.message}`);
39
39
  }
40
40
  catch (e) {
41
41
  throw new devkit_1.AggregateCreateNodesError([
42
42
  [
43
43
  gradlewFile,
44
- new Error(`Could not run 'projectReportAll' or 'projectReport' task. Please run 'nx generate @nx/gradle:init' to generate the necessary tasks.`),
44
+ new Error(`Could not run 'projectReportAll' or 'projectReport' task. Please run 'nx generate @nx/gradle:init' to generate the necessary tasks. ${e.message}`),
45
45
  ],
46
46
  ], []);
47
47
  }
@@ -13,7 +13,7 @@ exports.GRADLE_TEST_FILES = [
13
13
  '**/src/test/kotlin/**/*Tests.kt',
14
14
  ];
15
15
  exports.gradleConfigGlob = (0, globs_1.combineGlobPatterns)(...Array.from(exports.GRADLE_BUILD_FILES).map((file) => `**/${file}`));
16
- exports.gradleConfigAndTestGlob = (0, globs_1.combineGlobPatterns)(...Array.from(exports.GRADLE_BUILD_FILES).map((file) => `**/${file}`), ...Array.from(exports.GRALDEW_FILES).map((file) => `**/${file}`), ...exports.GRADLE_TEST_FILES);
16
+ exports.gradleConfigAndTestGlob = (0, globs_1.combineGlobPatterns)(...Array.from(exports.GRADLE_BUILD_FILES), ...Array.from(exports.GRALDEW_FILES), ...Array.from(exports.GRADLE_BUILD_FILES).map((file) => `**/${file}`), ...Array.from(exports.GRALDEW_FILES).map((file) => `**/${file}`), ...exports.GRADLE_TEST_FILES);
17
17
  /**
18
18
  * This function split config files into build files, settings files, test files and project roots
19
19
  * @param files list of files to split