@nx/gradle 21.0.0-canary.20250423-16fc551 → 21.0.0-canary.20250424-e23b25f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/executors.json +3 -0
  2. package/migrations.json +6 -0
  3. package/package.json +4 -2
  4. package/plugin-v1.d.ts +2 -0
  5. package/plugin-v1.js +8 -0
  6. package/plugin.d.ts +1 -1
  7. package/plugin.js +1 -2
  8. package/project-graph/project.json +43 -0
  9. package/project-graph/publish-maven.d.ts +1 -0
  10. package/project-graph/publish-maven.js +103 -0
  11. package/src/generators/ci-workflow/files/circleci/.circleci/config.yml.template +1 -1
  12. package/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml.template +3 -3
  13. package/src/generators/init/init.js +28 -44
  14. package/src/migrations/19-4-0/add-project-report-all.d.ts +4 -0
  15. package/src/migrations/19-4-0/add-project-report-all.js +83 -2
  16. package/src/migrations/21-0-0/change-plugin-to-v1.d.ts +2 -0
  17. package/src/migrations/21-0-0/change-plugin-to-v1.js +26 -0
  18. package/src/plugin/dependencies.d.ts +2 -1
  19. package/src/plugin/dependencies.js +30 -55
  20. package/src/plugin/nodes.d.ts +3 -16
  21. package/src/plugin/nodes.js +17 -228
  22. package/src/plugin/utils/__mocks__/gradle_composite.json +38 -0
  23. package/src/plugin/utils/__mocks__/gradle_nx_list.json +590 -0
  24. package/src/plugin/utils/__mocks__/gradle_tutorial.json +344 -0
  25. package/src/plugin/utils/get-project-graph-from-gradle-plugin.d.ts +25 -0
  26. package/src/plugin/utils/get-project-graph-from-gradle-plugin.js +113 -0
  27. package/src/plugin/utils/get-project-graph-lines.d.ts +2 -0
  28. package/src/plugin/utils/get-project-graph-lines.js +66 -0
  29. package/src/plugin/utils/gradle-plugin-options.d.ts +6 -0
  30. package/src/plugin/utils/gradle-plugin-options.js +8 -0
  31. package/src/plugin-v1/dependencies.d.ts +2 -0
  32. package/src/plugin-v1/dependencies.js +64 -0
  33. package/src/plugin-v1/nodes.d.ts +20 -0
  34. package/src/plugin-v1/nodes.js +266 -0
  35. package/src/{utils → plugin-v1/utils}/get-gradle-report.d.ts +2 -2
  36. package/src/{utils → plugin-v1/utils}/get-gradle-report.js +19 -23
  37. package/src/{utils → plugin-v1/utils}/get-project-report-lines.d.ts +0 -2
  38. package/src/{utils → plugin-v1/utils}/get-project-report-lines.js +2 -10
  39. package/src/utils/exec-gradle.d.ts +5 -3
  40. package/src/utils/exec-gradle.js +12 -5
  41. package/src/utils/split-config-files.js +2 -0
  42. package/src/utils/versions.d.ts +2 -0
  43. package/src/utils/versions.js +3 -1
@@ -0,0 +1,344 @@
1
+ {
2
+ "nodes": {
3
+ "proj": {
4
+ "targets": {
5
+ "buildEnvironment": {
6
+ "cache": true,
7
+ "metadata": {
8
+ "description": "Displays all buildscript dependencies declared in root project \u0027gradle-tutorial\u0027.",
9
+ "technologies": ["gradle"]
10
+ },
11
+ "command": "./gradlew :buildEnvironment",
12
+ "options": { "cwd": "proj" }
13
+ }
14
+ },
15
+ "metadata": {
16
+ "targetGroups": {
17
+ "help": ["buildEnvironment"]
18
+ },
19
+ "technologies": ["gradle"]
20
+ },
21
+ "name": "gradle-tutorial"
22
+ },
23
+ "proj/application": {
24
+ "targets": {
25
+ "ci--DemoApplicationTest10": {
26
+ "inputs": [
27
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest10.java"
28
+ ],
29
+ "outputs": [
30
+ "{projectRoot}/build/classes/java/test",
31
+ "{projectRoot}/build/generated/sources/annotationProcessor/java/test",
32
+ "{projectRoot}/build/generated/sources/headers/java/test",
33
+ "{projectRoot}/build/tmp/compileTestJava/previous-compilation-data.bin"
34
+ ],
35
+ "cache": true,
36
+ "dependsOn": [
37
+ "application:classes",
38
+ "application:compileJava",
39
+ "library:jar"
40
+ ],
41
+ "metadata": {
42
+ "description": "Runs Gradle test proj/application/src/test/java/com/example/multimodule/application/DemoApplicationTest10.java in CI",
43
+ "technologies": ["gradle"]
44
+ },
45
+ "command": "./gradlew :application:test --tests DemoApplicationTest10",
46
+ "options": { "cwd": "proj" }
47
+ },
48
+ "ci--DemoApplicationTest7": {
49
+ "inputs": [
50
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest7.java"
51
+ ],
52
+ "outputs": [
53
+ "{projectRoot}/build/classes/java/test",
54
+ "{projectRoot}/build/generated/sources/annotationProcessor/java/test",
55
+ "{projectRoot}/build/generated/sources/headers/java/test",
56
+ "{projectRoot}/build/tmp/compileTestJava/previous-compilation-data.bin"
57
+ ],
58
+ "cache": true,
59
+ "dependsOn": [
60
+ "application:classes",
61
+ "application:compileJava",
62
+ "library:jar"
63
+ ],
64
+ "metadata": {
65
+ "description": "Runs Gradle test proj/application/src/test/java/com/example/multimodule/application/DemoApplicationTest7.java in CI",
66
+ "technologies": ["gradle"]
67
+ },
68
+ "command": "./gradlew :application:test --tests DemoApplicationTest7",
69
+ "options": { "cwd": "proj" }
70
+ },
71
+ "ci--DemoApplicationTest6": {
72
+ "inputs": [
73
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest6.java"
74
+ ],
75
+ "outputs": [
76
+ "{projectRoot}/build/classes/java/test",
77
+ "{projectRoot}/build/generated/sources/annotationProcessor/java/test",
78
+ "{projectRoot}/build/generated/sources/headers/java/test",
79
+ "{projectRoot}/build/tmp/compileTestJava/previous-compilation-data.bin"
80
+ ],
81
+ "cache": true,
82
+ "dependsOn": [
83
+ "application:classes",
84
+ "application:compileJava",
85
+ "library:jar"
86
+ ],
87
+ "metadata": {
88
+ "description": "Runs Gradle test proj/application/src/test/java/com/example/multimodule/application/DemoApplicationTest6.java in CI",
89
+ "technologies": ["gradle"]
90
+ },
91
+ "command": "./gradlew :application:test --tests DemoApplicationTest6",
92
+ "options": { "cwd": "proj" }
93
+ },
94
+ "ci--DemoApplicationTest3": {
95
+ "inputs": [
96
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest3.java"
97
+ ],
98
+ "outputs": [
99
+ "{projectRoot}/build/classes/java/test",
100
+ "{projectRoot}/build/generated/sources/annotationProcessor/java/test",
101
+ "{projectRoot}/build/generated/sources/headers/java/test",
102
+ "{projectRoot}/build/tmp/compileTestJava/previous-compilation-data.bin"
103
+ ],
104
+ "cache": true,
105
+ "dependsOn": [
106
+ "application:classes",
107
+ "application:compileJava",
108
+ "library:jar"
109
+ ],
110
+ "metadata": {
111
+ "description": "Runs Gradle test proj/application/src/test/java/com/example/multimodule/application/DemoApplicationTest3.java in CI",
112
+ "technologies": ["gradle"]
113
+ },
114
+ "command": "./gradlew :application:test --tests DemoApplicationTest3",
115
+ "options": { "cwd": "proj" }
116
+ },
117
+ "ci--DemoApplicationTest2": {
118
+ "inputs": [
119
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest2.java"
120
+ ],
121
+ "outputs": [
122
+ "{projectRoot}/build/classes/java/test",
123
+ "{projectRoot}/build/generated/sources/annotationProcessor/java/test",
124
+ "{projectRoot}/build/generated/sources/headers/java/test",
125
+ "{projectRoot}/build/tmp/compileTestJava/previous-compilation-data.bin"
126
+ ],
127
+ "cache": true,
128
+ "dependsOn": [
129
+ "application:classes",
130
+ "application:compileJava",
131
+ "library:jar"
132
+ ],
133
+ "metadata": {
134
+ "description": "Runs Gradle test proj/application/src/test/java/com/example/multimodule/application/DemoApplicationTest2.java in CI",
135
+ "technologies": ["gradle"]
136
+ },
137
+ "command": "./gradlew :application:test --tests DemoApplicationTest2",
138
+ "options": { "cwd": "proj" }
139
+ },
140
+ "ci--DemoApplicationTest9": {
141
+ "inputs": [
142
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest9.java"
143
+ ],
144
+ "outputs": [
145
+ "{projectRoot}/build/classes/java/test",
146
+ "{projectRoot}/build/generated/sources/annotationProcessor/java/test",
147
+ "{projectRoot}/build/generated/sources/headers/java/test",
148
+ "{projectRoot}/build/tmp/compileTestJava/previous-compilation-data.bin"
149
+ ],
150
+ "cache": true,
151
+ "dependsOn": [
152
+ "application:classes",
153
+ "application:compileJava",
154
+ "library:jar"
155
+ ],
156
+ "metadata": {
157
+ "description": "Runs Gradle test proj/application/src/test/java/com/example/multimodule/application/DemoApplicationTest9.java in CI",
158
+ "technologies": ["gradle"]
159
+ },
160
+ "command": "./gradlew :application:test --tests DemoApplicationTest9",
161
+ "options": { "cwd": "proj" }
162
+ },
163
+ "ci--DemoApplicationTest": {
164
+ "inputs": [
165
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest.java"
166
+ ],
167
+ "outputs": [
168
+ "{projectRoot}/build/classes/java/test",
169
+ "{projectRoot}/build/generated/sources/annotationProcessor/java/test",
170
+ "{projectRoot}/build/generated/sources/headers/java/test",
171
+ "{projectRoot}/build/tmp/compileTestJava/previous-compilation-data.bin"
172
+ ],
173
+ "cache": true,
174
+ "dependsOn": [
175
+ "application:classes",
176
+ "application:compileJava",
177
+ "library:jar"
178
+ ],
179
+ "metadata": {
180
+ "description": "Runs Gradle test proj/application/src/test/java/com/example/multimodule/application/DemoApplicationTest.java in CI",
181
+ "technologies": ["gradle"]
182
+ },
183
+ "command": "./gradlew :application:test --tests DemoApplicationTest",
184
+ "options": { "cwd": "proj" }
185
+ },
186
+ "ci--DemoApplicationTest5": {
187
+ "inputs": [
188
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest5.java"
189
+ ],
190
+ "outputs": [
191
+ "{projectRoot}/build/classes/java/test",
192
+ "{projectRoot}/build/generated/sources/annotationProcessor/java/test",
193
+ "{projectRoot}/build/generated/sources/headers/java/test",
194
+ "{projectRoot}/build/tmp/compileTestJava/previous-compilation-data.bin"
195
+ ],
196
+ "cache": true,
197
+ "dependsOn": [
198
+ "application:classes",
199
+ "application:compileJava",
200
+ "library:jar"
201
+ ],
202
+ "metadata": {
203
+ "description": "Runs Gradle test proj/application/src/test/java/com/example/multimodule/application/DemoApplicationTest5.java in CI",
204
+ "technologies": ["gradle"]
205
+ },
206
+ "command": "./gradlew :application:test --tests DemoApplicationTest5",
207
+ "options": { "cwd": "proj" }
208
+ },
209
+ "ci--DemoApplicationTest4": {
210
+ "inputs": [
211
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest4.java"
212
+ ],
213
+ "outputs": [
214
+ "{projectRoot}/build/classes/java/test",
215
+ "{projectRoot}/build/generated/sources/annotationProcessor/java/test",
216
+ "{projectRoot}/build/generated/sources/headers/java/test",
217
+ "{projectRoot}/build/tmp/compileTestJava/previous-compilation-data.bin"
218
+ ],
219
+ "cache": true,
220
+ "dependsOn": [
221
+ "application:classes",
222
+ "application:compileJava",
223
+ "library:jar"
224
+ ],
225
+ "metadata": {
226
+ "description": "Runs Gradle test proj/application/src/test/java/com/example/multimodule/application/DemoApplicationTest4.java in CI",
227
+ "technologies": ["gradle"]
228
+ },
229
+ "command": "./gradlew :application:test --tests DemoApplicationTest4",
230
+ "options": { "cwd": "proj" }
231
+ },
232
+ "ci--DemoApplicationTest8": {
233
+ "inputs": [
234
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest8.java"
235
+ ],
236
+ "outputs": [
237
+ "{projectRoot}/build/classes/java/test",
238
+ "{projectRoot}/build/generated/sources/annotationProcessor/java/test",
239
+ "{projectRoot}/build/generated/sources/headers/java/test",
240
+ "{projectRoot}/build/tmp/compileTestJava/previous-compilation-data.bin"
241
+ ],
242
+ "cache": true,
243
+ "dependsOn": [
244
+ "application:classes",
245
+ "application:compileJava",
246
+ "library:jar"
247
+ ],
248
+ "metadata": {
249
+ "description": "Runs Gradle test proj/application/src/test/java/com/example/multimodule/application/DemoApplicationTest8.java in CI",
250
+ "technologies": ["gradle"]
251
+ },
252
+ "command": "./gradlew :application:test --tests DemoApplicationTest8",
253
+ "options": { "cwd": "proj" }
254
+ },
255
+ "ci": {
256
+ "inputs": [
257
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest10.java",
258
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest7.java",
259
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest6.java",
260
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest3.java",
261
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest2.java",
262
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest9.java",
263
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest.java",
264
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest5.java",
265
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest4.java",
266
+ "{projectRoot}/src/test/java/com/example/multimodule/application/DemoApplicationTest8.java"
267
+ ],
268
+ "outputs": [
269
+ "{projectRoot}/build/classes/java/test",
270
+ "{projectRoot}/build/generated/sources/annotationProcessor/java/test",
271
+ "{projectRoot}/build/generated/sources/headers/java/test",
272
+ "{projectRoot}/build/tmp/compileTestJava/previous-compilation-data.bin"
273
+ ],
274
+ "cache": true,
275
+ "dependsOn": [
276
+ {
277
+ "target": "ci--DemoApplicationTest10",
278
+ "projects": "self",
279
+ "params": "forward"
280
+ },
281
+ {
282
+ "target": "ci--DemoApplicationTest7",
283
+ "projects": "self",
284
+ "params": "forward"
285
+ },
286
+ {
287
+ "target": "ci--DemoApplicationTest6",
288
+ "projects": "self",
289
+ "params": "forward"
290
+ },
291
+ {
292
+ "target": "ci--DemoApplicationTest3",
293
+ "projects": "self",
294
+ "params": "forward"
295
+ },
296
+ {
297
+ "target": "ci--DemoApplicationTest2",
298
+ "projects": "self",
299
+ "params": "forward"
300
+ },
301
+ {
302
+ "target": "ci--DemoApplicationTest9",
303
+ "projects": "self",
304
+ "params": "forward"
305
+ },
306
+ {
307
+ "target": "ci--DemoApplicationTest",
308
+ "projects": "self",
309
+ "params": "forward"
310
+ },
311
+ {
312
+ "target": "ci--DemoApplicationTest5",
313
+ "projects": "self",
314
+ "params": "forward"
315
+ },
316
+ {
317
+ "target": "ci--DemoApplicationTest4",
318
+ "projects": "self",
319
+ "params": "forward"
320
+ },
321
+ {
322
+ "target": "ci--DemoApplicationTest8",
323
+ "projects": "self",
324
+ "params": "forward"
325
+ }
326
+ ],
327
+ "metadata": {
328
+ "description": "Runs Gradle Tests in CI",
329
+ "technologies": ["gradle"]
330
+ },
331
+ "options": { "cwd": "proj" },
332
+ "executor": "nx:noop"
333
+ }
334
+ },
335
+ "metadata": {
336
+ "targetGroups": {
337
+ "verification": ["ci"]
338
+ },
339
+ "technologies": ["gradle"]
340
+ },
341
+ "name": "application"
342
+ }
343
+ }
344
+ }
@@ -0,0 +1,25 @@
1
+ import { ProjectConfiguration, ProjectGraphExternalNode, StaticDependency } from '@nx/devkit';
2
+ import { GradlePluginOptions } from './gradle-plugin-options';
3
+ export interface ProjectGraphReport {
4
+ nodes: {
5
+ [appRoot: string]: Partial<ProjectConfiguration>;
6
+ };
7
+ dependencies: Array<StaticDependency>;
8
+ externalNodes?: Record<string, ProjectGraphExternalNode>;
9
+ }
10
+ export interface ProjectGraphReportCache extends ProjectGraphReport {
11
+ hash: string;
12
+ }
13
+ export declare function writeProjectGraphReportToCache(cachePath: string, results: ProjectGraphReport): void;
14
+ export declare function getCurrentProjectGraphReport(): ProjectGraphReport;
15
+ /**
16
+ * This function populates the gradle report cache.
17
+ * For each gradlew file, it runs the `nxProjectGraph` task and processes the output.
18
+ * It will throw an error if both tasks fail.
19
+ * It will accumulate the output of all gradlew files.
20
+ * @param workspaceRoot
21
+ * @param gradlewFiles absolute paths to all gradlew files in the workspace
22
+ * @returns Promise<void>
23
+ */
24
+ export declare function populateProjectGraph(workspaceRoot: string, gradlewFiles: string[], options: GradlePluginOptions): Promise<void>;
25
+ export declare function processNxProjectGraph(projectGraphLines: string[]): ProjectGraphReport;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeProjectGraphReportToCache = writeProjectGraphReportToCache;
4
+ exports.getCurrentProjectGraphReport = getCurrentProjectGraphReport;
5
+ exports.populateProjectGraph = populateProjectGraph;
6
+ exports.processNxProjectGraph = processNxProjectGraph;
7
+ const node_fs_1 = require("node:fs");
8
+ const node_path_1 = require("node:path");
9
+ const devkit_1 = require("@nx/devkit");
10
+ const workspace_context_1 = require("nx/src/utils/workspace-context");
11
+ const split_config_files_1 = require("../../utils/split-config-files");
12
+ const cache_directory_1 = require("nx/src/utils/cache-directory");
13
+ const get_project_graph_lines_1 = require("./get-project-graph-lines");
14
+ const devkit_internals_1 = require("nx/src/devkit-internals");
15
+ function readProjectGraphReportCache(cachePath, hash) {
16
+ const projectGraphReportCache = (0, node_fs_1.existsSync)(cachePath)
17
+ ? (0, devkit_1.readJsonFile)(cachePath)
18
+ : undefined;
19
+ if (!projectGraphReportCache || projectGraphReportCache.hash !== hash) {
20
+ return;
21
+ }
22
+ return projectGraphReportCache;
23
+ }
24
+ function writeProjectGraphReportToCache(cachePath, results) {
25
+ let projectGraphReportJson = {
26
+ hash: gradleCurrentConfigHash,
27
+ ...results,
28
+ };
29
+ (0, devkit_1.writeJsonFile)(cachePath, projectGraphReportJson);
30
+ }
31
+ let projectGraphReportCache;
32
+ let gradleCurrentConfigHash;
33
+ let projectGraphReportCachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, 'gradle-nodes.hash');
34
+ function getCurrentProjectGraphReport() {
35
+ if (!projectGraphReportCache) {
36
+ throw new devkit_1.AggregateCreateNodesError([
37
+ [
38
+ null,
39
+ new Error(`Expected cached gradle report. Please open an issue at https://github.com/nrwl/nx/issues/new/choose`),
40
+ ],
41
+ ], []);
42
+ }
43
+ return projectGraphReportCache;
44
+ }
45
+ /**
46
+ * This function populates the gradle report cache.
47
+ * For each gradlew file, it runs the `nxProjectGraph` task and processes the output.
48
+ * It will throw an error if both tasks fail.
49
+ * It will accumulate the output of all gradlew files.
50
+ * @param workspaceRoot
51
+ * @param gradlewFiles absolute paths to all gradlew files in the workspace
52
+ * @returns Promise<void>
53
+ */
54
+ async function populateProjectGraph(workspaceRoot, gradlewFiles, options) {
55
+ const gradleConfigHash = (0, devkit_1.hashArray)([
56
+ await (0, workspace_context_1.hashWithWorkspaceContext)(workspaceRoot, [split_config_files_1.gradleConfigAndTestGlob]),
57
+ (0, devkit_internals_1.hashObject)(options),
58
+ process.env.CI,
59
+ ]);
60
+ projectGraphReportCache ??= readProjectGraphReportCache(projectGraphReportCachePath, gradleConfigHash);
61
+ if (projectGraphReportCache &&
62
+ (!gradleCurrentConfigHash || gradleConfigHash === gradleCurrentConfigHash)) {
63
+ return;
64
+ }
65
+ const gradleProjectGraphReportStart = performance.mark('gradleProjectGraphReport:start');
66
+ const projectGraphLines = await gradlewFiles.reduce(async (projectGraphLines, gradlewFile) => {
67
+ const getNxProjectGraphLinesStart = performance.mark(`${gradlewFile}GetNxProjectGraphLines:start`);
68
+ const allLines = await projectGraphLines;
69
+ const currentLines = await (0, get_project_graph_lines_1.getNxProjectGraphLines)(gradlewFile, gradleConfigHash, options);
70
+ const getNxProjectGraphLinesEnd = performance.mark(`${gradlewFile}GetNxProjectGraphLines:end`);
71
+ performance.measure(`${gradlewFile}GetNxProjectGraphLines`, getNxProjectGraphLinesStart.name, getNxProjectGraphLinesEnd.name);
72
+ return [...allLines, ...currentLines];
73
+ }, Promise.resolve([]));
74
+ const gradleProjectGraphReportEnd = performance.mark('gradleProjectGraphReport:end');
75
+ performance.measure('gradleProjectGraphReport', gradleProjectGraphReportStart.name, gradleProjectGraphReportEnd.name);
76
+ gradleCurrentConfigHash = gradleConfigHash;
77
+ projectGraphReportCache = processNxProjectGraph(projectGraphLines);
78
+ writeProjectGraphReportToCache(projectGraphReportCachePath, projectGraphReportCache);
79
+ }
80
+ function processNxProjectGraph(projectGraphLines) {
81
+ let index = 0;
82
+ let projectGraphReportForAllProjects = {
83
+ nodes: {},
84
+ dependencies: [],
85
+ externalNodes: {},
86
+ };
87
+ while (index < projectGraphLines.length) {
88
+ const line = projectGraphLines[index].trim();
89
+ if (line.startsWith('> Task ') && line.endsWith(':nxProjectGraph')) {
90
+ while (index < projectGraphLines.length &&
91
+ !projectGraphLines[index].includes('.json')) {
92
+ index++;
93
+ }
94
+ const file = projectGraphLines[index];
95
+ const projectGraphReportJson = (0, devkit_1.readJsonFile)(file);
96
+ projectGraphReportForAllProjects.nodes = {
97
+ ...projectGraphReportForAllProjects.nodes,
98
+ ...projectGraphReportJson.nodes,
99
+ };
100
+ if (projectGraphReportJson.dependencies) {
101
+ projectGraphReportForAllProjects.dependencies.push(...projectGraphReportJson.dependencies);
102
+ }
103
+ if (Object.keys(projectGraphReportJson.externalNodes ?? {}).length > 0) {
104
+ projectGraphReportForAllProjects.externalNodes = {
105
+ ...projectGraphReportForAllProjects.externalNodes,
106
+ ...projectGraphReportJson.externalNodes,
107
+ };
108
+ }
109
+ }
110
+ index++;
111
+ }
112
+ return projectGraphReportForAllProjects;
113
+ }
@@ -0,0 +1,2 @@
1
+ import { GradlePluginOptions } from './gradle-plugin-options';
2
+ export declare function getNxProjectGraphLines(gradlewFile: string, gradleConfigHash: string, gradlePluginOptions: GradlePluginOptions): Promise<string[]>;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNxProjectGraphLines = getNxProjectGraphLines;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const exec_gradle_1 = require("../../utils/exec-gradle");
6
+ const node_path_1 = require("node:path");
7
+ async function getNxProjectGraphLines(gradlewFile, gradleConfigHash, gradlePluginOptions) {
8
+ if (process.env.VERCEL) {
9
+ // skip on Vercel
10
+ return [];
11
+ }
12
+ let nxProjectGraphBuffer;
13
+ const gradlePluginOptionsArgs = Object.entries(gradlePluginOptions ?? {})?.map(([key, value]) => `-P${key}=${value}`) ?? [];
14
+ try {
15
+ nxProjectGraphBuffer = await (0, exec_gradle_1.execGradleAsync)(gradlewFile, [
16
+ 'nxProjectGraph',
17
+ `-Phash=${gradleConfigHash}`,
18
+ '--no-configuration-cache', // disable configuration cache
19
+ '--parallel', // add parallel to improve performance
20
+ '--build-cache', // enable build cache
21
+ '--warning-mode',
22
+ 'none',
23
+ ...gradlePluginOptionsArgs,
24
+ `-Pcwd=${(0, node_path_1.dirname)(gradlewFile)}`,
25
+ `-PworkspaceRoot=${devkit_1.workspaceRoot}`,
26
+ process.env.NX_VERBOSE_LOGGING ? '--info' : '',
27
+ ]);
28
+ }
29
+ catch (e) {
30
+ if (e.toString()?.includes('ERROR: JAVA_HOME')) {
31
+ throw new devkit_1.AggregateCreateNodesError([
32
+ [
33
+ gradlewFile,
34
+ new Error(`Could not find Java. Please install Java and try again: https://www.java.com/en/download/help/index_installing.html.\n\r${e.toString()}`),
35
+ ],
36
+ ], []);
37
+ }
38
+ else if (e.toString()?.includes(`Task 'nxProjectGraph' not found`)) {
39
+ throw new devkit_1.AggregateCreateNodesError([
40
+ [
41
+ gradlewFile,
42
+ new Error(`Could not run 'nxProjectGraph' task. Please run 'nx generate @nx/gradle:init' to generate the necessary tasks.\n\r${e.toString()}`),
43
+ ],
44
+ ], []);
45
+ }
46
+ else {
47
+ throw new devkit_1.AggregateCreateNodesError([
48
+ [
49
+ gradlewFile,
50
+ new Error(`Could not run 'nxProjectGraph' Gradle task. Please install Gradle and try again: https://gradle.org/install/.\r\n${e.toString()}`),
51
+ ],
52
+ ], []);
53
+ }
54
+ }
55
+ const projectGraphLines = nxProjectGraphBuffer
56
+ .toString()
57
+ .split(exec_gradle_1.newLineSeparator)
58
+ .filter((line) => line.trim() !== '');
59
+ if (process.env.NX_VERBOSE_LOGGING === 'true') {
60
+ devkit_1.output.log({
61
+ title: `Successfully ran 'nxProjectGraph' task using ${gradlewFile} with hash ${gradleConfigHash}`,
62
+ bodyLines: projectGraphLines,
63
+ });
64
+ }
65
+ return projectGraphLines;
66
+ }
@@ -0,0 +1,6 @@
1
+ export interface GradlePluginOptions {
2
+ testTargetName?: string;
3
+ ciTargetName?: string;
4
+ [taskTargetName: string]: string | undefined | boolean;
5
+ }
6
+ export declare function normalizeOptions(options: GradlePluginOptions): GradlePluginOptions;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeOptions = normalizeOptions;
4
+ function normalizeOptions(options) {
5
+ options ??= {};
6
+ options.testTargetName ??= 'test';
7
+ return options;
8
+ }
@@ -0,0 +1,2 @@
1
+ import { CreateDependencies } from '@nx/devkit';
2
+ export declare const createDependencies: CreateDependencies;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDependencies = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const node_path_1 = require("node:path");
6
+ const get_gradle_report_1 = require("./utils/get-gradle-report");
7
+ const split_config_files_1 = require("../utils/split-config-files");
8
+ const createDependencies = async (_, context) => {
9
+ const gradleFiles = findGradleFiles(context.filesToProcess);
10
+ if (gradleFiles.length === 0) {
11
+ return [];
12
+ }
13
+ const gradleDependenciesStart = performance.mark('gradleDependencies:start');
14
+ const { gradleFileToGradleProjectMap, gradleProjectNameToProjectRootMap, gradleProjectToDepsMap, gradleProjectToChildProjects, } = (0, get_gradle_report_1.getCurrentGradleReport)();
15
+ const dependencies = new Set();
16
+ for (const gradleFile of gradleFiles) {
17
+ const gradleProject = gradleFileToGradleProjectMap.get(gradleFile);
18
+ const projectName = Object.values(context.projects).find((project) => project.root === (0, node_path_1.dirname)(gradleFile))?.name;
19
+ const dependedProjects = gradleProjectToDepsMap.get(gradleProject);
20
+ if (projectName && dependedProjects?.size) {
21
+ dependedProjects?.forEach((dependedProject) => {
22
+ const targetProjectRoot = gradleProjectNameToProjectRootMap.get(dependedProject);
23
+ const targetProjectName = Object.values(context.projects).find((project) => project.root === targetProjectRoot)?.name;
24
+ if (targetProjectName) {
25
+ const dependency = {
26
+ source: projectName,
27
+ target: targetProjectName,
28
+ type: devkit_1.DependencyType.static,
29
+ sourceFile: gradleFile,
30
+ };
31
+ (0, devkit_1.validateDependency)(dependency, context);
32
+ dependencies.add(dependency);
33
+ }
34
+ });
35
+ }
36
+ gradleProjectToChildProjects.get(gradleProject)?.forEach((childProject) => {
37
+ if (childProject) {
38
+ const dependency = {
39
+ source: projectName,
40
+ target: childProject,
41
+ type: devkit_1.DependencyType.static,
42
+ sourceFile: gradleFile,
43
+ };
44
+ (0, devkit_1.validateDependency)(dependency, context);
45
+ dependencies.add(dependency);
46
+ }
47
+ });
48
+ }
49
+ const gradleDependenciesEnd = performance.mark('gradleDependencies:end');
50
+ performance.measure('gradleDependencies', gradleDependenciesStart.name, gradleDependenciesEnd.name);
51
+ return Array.from(dependencies);
52
+ };
53
+ exports.createDependencies = createDependencies;
54
+ function findGradleFiles(fileMap) {
55
+ const gradleFiles = [];
56
+ for (const [_, files] of Object.entries(fileMap.projectFileMap)) {
57
+ for (const file of files) {
58
+ if (split_config_files_1.GRADLE_BUILD_FILES.has((0, node_path_1.basename)(file.file))) {
59
+ gradleFiles.push(file.file);
60
+ }
61
+ }
62
+ }
63
+ return gradleFiles;
64
+ }
@@ -0,0 +1,20 @@
1
+ import { CreateNodes, CreateNodesV2, ProjectConfiguration, CreateNodesFunction } from '@nx/devkit';
2
+ import { GradleReport } from './utils/get-gradle-report';
3
+ export interface GradlePluginOptions {
4
+ includeSubprojectsTasks?: boolean;
5
+ ciTargetName?: string;
6
+ testTargetName?: string;
7
+ classesTargetName?: string;
8
+ buildTargetName?: string;
9
+ [taskTargetName: string]: string | undefined | boolean;
10
+ }
11
+ type GradleTargets = Record<string, Partial<ProjectConfiguration>>;
12
+ export declare function writeTargetsToCache(cachePath: string, results: GradleTargets): void;
13
+ export declare const createNodesV2: CreateNodesV2<GradlePluginOptions>;
14
+ export declare const makeCreateNodesForGradleConfigFile: (gradleReport: GradleReport, targetsCache?: GradleTargets, gradleProjectRootToTestFilesMap?: Record<string, string[]>) => CreateNodesFunction;
15
+ /**
16
+ @deprecated This is replaced with {@link createNodesV2}. Update your plugin to export its own `createNodesV2` function that wraps this one instead.
17
+ This function will change to the v2 function in Nx 20.
18
+ */
19
+ export declare const createNodes: CreateNodes<GradlePluginOptions>;
20
+ export {};