@nx/gradle 20.5.0-beta.3 → 20.5.0-canary.20250128-e0c49d3
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.
- package/generators.json +1 -2
- package/package.json +2 -2
- package/src/plugin/dependencies.d.ts +2 -1
- package/src/plugin/dependencies.js +49 -16
- package/src/plugin/nodes.js +1 -1
- package/src/utils/exec-gradle.js +0 -2
- package/src/utils/get-gradle-report.d.ts +4 -5
- package/src/utils/get-gradle-report.js +1 -42
- package/src/utils/get-project-report-lines.js +1 -9
package/generators.json
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
"init": {
|
|
6
6
|
"factory": "./src/generators/init/init#initGenerator",
|
|
7
7
|
"schema": "./src/generators/init/schema.json",
|
|
8
|
-
"description": "Initializes a Gradle project in the current workspace"
|
|
9
|
-
"hidden": true
|
|
8
|
+
"description": "Initializes a Gradle project in the current workspace"
|
|
10
9
|
},
|
|
11
10
|
"ci-workflow": {
|
|
12
11
|
"factory": "./src/generators/ci-workflow/generator",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/gradle",
|
|
3
|
-
"version": "20.5.0-
|
|
3
|
+
"version": "20.5.0-canary.20250128-e0c49d3",
|
|
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.5.0-
|
|
37
|
+
"@nx/devkit": "20.5.0-canary.20250128-e0c49d3"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { CreateDependencies } from '@nx/devkit';
|
|
1
|
+
import { CreateDependencies, CreateDependenciesContext, RawProjectGraphDependency } from '@nx/devkit';
|
|
2
2
|
export declare const createDependencies: CreateDependencies;
|
|
3
|
+
export declare function processGradleDependencies(depsFile: string, gradleProjectNameToProjectRoot: Map<string, string>, sourceProjectName: string, gradleFile: string, context: CreateDependenciesContext, dependencies: Set<RawProjectGraphDependency>): void;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createDependencies = void 0;
|
|
4
|
+
exports.processGradleDependencies = processGradleDependencies;
|
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
5
7
|
const node_path_1 = require("node:path");
|
|
6
8
|
const get_gradle_report_1 = require("../utils/get-gradle-report");
|
|
7
9
|
const split_config_files_1 = require("../utils/split-config-files");
|
|
10
|
+
const get_project_report_lines_1 = require("../utils/get-project-report-lines");
|
|
8
11
|
const createDependencies = async (_, context) => {
|
|
9
12
|
const gradleFiles = findGradleFiles(context.filesToProcess);
|
|
10
13
|
if (gradleFiles.length === 0) {
|
|
@@ -16,22 +19,9 @@ const createDependencies = async (_, context) => {
|
|
|
16
19
|
for (const gradleFile of gradleFiles) {
|
|
17
20
|
const gradleProject = gradleFileToGradleProjectMap.get(gradleFile);
|
|
18
21
|
const projectName = Object.values(context.projects).find((project) => project.root === (0, node_path_1.dirname)(gradleFile))?.name;
|
|
19
|
-
const
|
|
20
|
-
if (projectName &&
|
|
21
|
-
|
|
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
|
-
});
|
|
22
|
+
const depsFile = buildFileToDepsMap.get(gradleFile);
|
|
23
|
+
if (projectName && depsFile) {
|
|
24
|
+
processGradleDependencies(depsFile, gradleProjectNameToProjectRootMap, projectName, gradleFile, context, dependencies);
|
|
35
25
|
}
|
|
36
26
|
gradleProjectToChildProjects.get(gradleProject)?.forEach((childProject) => {
|
|
37
27
|
if (childProject) {
|
|
@@ -62,3 +52,46 @@ function findGradleFiles(fileMap) {
|
|
|
62
52
|
}
|
|
63
53
|
return gradleFiles;
|
|
64
54
|
}
|
|
55
|
+
function processGradleDependencies(depsFile, gradleProjectNameToProjectRoot, sourceProjectName, gradleFile, context, dependencies) {
|
|
56
|
+
const lines = (0, node_fs_1.readFileSync)(depsFile).toString().split(get_project_report_lines_1.newLineSeparator);
|
|
57
|
+
let inDeps = false;
|
|
58
|
+
for (const line of lines) {
|
|
59
|
+
if (line.startsWith('implementationDependenciesMetadata') ||
|
|
60
|
+
line.startsWith('compileClasspath')) {
|
|
61
|
+
inDeps = true;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (inDeps) {
|
|
65
|
+
if (line === '') {
|
|
66
|
+
inDeps = false;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const [indents, dep] = line.split('--- ');
|
|
70
|
+
if (indents === '\\' || indents === '+') {
|
|
71
|
+
let gradleProjectName;
|
|
72
|
+
if (dep.startsWith('project ')) {
|
|
73
|
+
gradleProjectName = dep
|
|
74
|
+
.substring('project '.length)
|
|
75
|
+
.replace(/ \(n\)$/, '')
|
|
76
|
+
.trim();
|
|
77
|
+
}
|
|
78
|
+
else if (dep.includes('-> project')) {
|
|
79
|
+
const [_, projectName] = dep.split('-> project');
|
|
80
|
+
gradleProjectName = projectName.trim();
|
|
81
|
+
}
|
|
82
|
+
const targetProjectRoot = gradleProjectNameToProjectRoot.get(gradleProjectName);
|
|
83
|
+
const targetProjectName = Object.values(context.projects).find((project) => project.root === targetProjectRoot)?.name;
|
|
84
|
+
if (targetProjectName) {
|
|
85
|
+
const dependency = {
|
|
86
|
+
source: sourceProjectName,
|
|
87
|
+
target: targetProjectName,
|
|
88
|
+
type: devkit_1.DependencyType.static,
|
|
89
|
+
sourceFile: gradleFile,
|
|
90
|
+
};
|
|
91
|
+
(0, devkit_1.validateDependency)(dependency, context);
|
|
92
|
+
dependencies.add(dependency);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
package/src/plugin/nodes.js
CHANGED
|
@@ -94,7 +94,7 @@ async function createGradleProject(gradleReport, gradleFilePath, options, contex
|
|
|
94
94
|
let tasks = [];
|
|
95
95
|
tasksSet.forEach((taskName) => {
|
|
96
96
|
tasks.push({
|
|
97
|
-
type: tasksTypeMap
|
|
97
|
+
type: tasksTypeMap.get(taskName),
|
|
98
98
|
name: taskName,
|
|
99
99
|
});
|
|
100
100
|
});
|
package/src/utils/exec-gradle.js
CHANGED
|
@@ -7,7 +7,6 @@ const devkit_1 = require("@nx/devkit");
|
|
|
7
7
|
const node_child_process_1 = require("node:child_process");
|
|
8
8
|
const node_fs_1 = require("node:fs");
|
|
9
9
|
const node_path_1 = require("node:path");
|
|
10
|
-
const run_commands_impl_1 = require("nx/src/executors/run-commands/run-commands.impl");
|
|
11
10
|
/**
|
|
12
11
|
* For gradle command, it needs to be run from the directory of the gradle binary
|
|
13
12
|
* @returns gradle binary file name
|
|
@@ -29,7 +28,6 @@ function execGradleAsync(gradleBinaryPath, args, execOptions = {}) {
|
|
|
29
28
|
shell: true,
|
|
30
29
|
windowsHide: true,
|
|
31
30
|
env: process.env,
|
|
32
|
-
maxBuffer: run_commands_impl_1.LARGE_BUFFER,
|
|
33
31
|
...execOptions,
|
|
34
32
|
});
|
|
35
33
|
let stdout = Buffer.from('');
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export interface GradleReport {
|
|
2
2
|
gradleFileToGradleProjectMap: Map<string, string>;
|
|
3
|
-
buildFileToDepsMap: Map<string,
|
|
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<
|
|
6
|
+
gradleProjectToTasksMap: Map<string, Set<String>>;
|
|
7
7
|
gradleProjectToProjectName: Map<string, string>;
|
|
8
8
|
gradleProjectNameToProjectRootMap: Map<string, string>;
|
|
9
9
|
gradleProjectToChildProjects: Map<string, string[]>;
|
|
@@ -11,10 +11,10 @@ export interface GradleReport {
|
|
|
11
11
|
export interface GradleReportJSON {
|
|
12
12
|
hash: string;
|
|
13
13
|
gradleFileToGradleProjectMap: Record<string, string>;
|
|
14
|
-
buildFileToDepsMap: Record<string,
|
|
14
|
+
buildFileToDepsMap: Record<string, string>;
|
|
15
15
|
gradleFileToOutputDirsMap: Record<string, Record<string, string>>;
|
|
16
16
|
gradleProjectToTasksTypeMap: Record<string, Record<string, string>>;
|
|
17
|
-
gradleProjectToTasksMap: Record<string, Array<
|
|
17
|
+
gradleProjectToTasksMap: Record<string, Array<String>>;
|
|
18
18
|
gradleProjectToProjectName: Record<string, string>;
|
|
19
19
|
gradleProjectNameToProjectRootMap: Record<string, string>;
|
|
20
20
|
gradleProjectToChildProjects: Record<string, string[]>;
|
|
@@ -33,4 +33,3 @@ export declare function getCurrentGradleReport(): GradleReport;
|
|
|
33
33
|
*/
|
|
34
34
|
export declare function populateGradleReport(workspaceRoot: string, gradlewFiles: string[]): Promise<void>;
|
|
35
35
|
export declare function processProjectReports(projectReportLines: string[]): GradleReport;
|
|
36
|
-
export declare function processGradleDependencies(depsFile: string): Set<string>;
|
|
@@ -4,7 +4,6 @@ exports.writeGradleReportToCache = writeGradleReportToCache;
|
|
|
4
4
|
exports.getCurrentGradleReport = getCurrentGradleReport;
|
|
5
5
|
exports.populateGradleReport = populateGradleReport;
|
|
6
6
|
exports.processProjectReports = processProjectReports;
|
|
7
|
-
exports.processGradleDependencies = processGradleDependencies;
|
|
8
7
|
const node_fs_1 = require("node:fs");
|
|
9
8
|
const node_path_1 = require("node:path");
|
|
10
9
|
const devkit_1 = require("@nx/devkit");
|
|
@@ -185,10 +184,7 @@ function processProjectReports(projectReportLines) {
|
|
|
185
184
|
}
|
|
186
185
|
const buildFile = (0, devkit_1.normalizePath)((0, node_path_1.relative)(devkit_1.workspaceRoot, absBuildFilePath));
|
|
187
186
|
const buildDir = (0, node_path_1.relative)(devkit_1.workspaceRoot, absBuildDirPath);
|
|
188
|
-
|
|
189
|
-
if (depsFile) {
|
|
190
|
-
buildFileToDepsMap.set(buildFile, processGradleDependencies(depsFile));
|
|
191
|
-
}
|
|
187
|
+
buildFileToDepsMap.set(buildFile, dependenciesMap.get(gradleProject));
|
|
192
188
|
outputDirMap.set('build', `{workspaceRoot}/${buildDir}`);
|
|
193
189
|
outputDirMap.set('classes', `{workspaceRoot}/${(0, node_path_1.join)(buildDir, 'classes')}`);
|
|
194
190
|
gradleFileToOutputDirsMap.set(buildFile, outputDirMap);
|
|
@@ -242,40 +238,3 @@ function processProjectReports(projectReportLines) {
|
|
|
242
238
|
gradleProjectToChildProjects,
|
|
243
239
|
};
|
|
244
240
|
}
|
|
245
|
-
function processGradleDependencies(depsFile) {
|
|
246
|
-
const dependedProjects = new Set();
|
|
247
|
-
const lines = (0, node_fs_1.readFileSync)(depsFile).toString().split(get_project_report_lines_1.newLineSeparator);
|
|
248
|
-
let inDeps = false;
|
|
249
|
-
for (const line of lines) {
|
|
250
|
-
if (line.startsWith('implementationDependenciesMetadata') ||
|
|
251
|
-
line.startsWith('compileClasspath')) {
|
|
252
|
-
inDeps = true;
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
if (inDeps) {
|
|
256
|
-
if (line === '') {
|
|
257
|
-
inDeps = false;
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
const [indents, dep] = line.split('--- ');
|
|
261
|
-
if (indents === '\\' || indents === '+') {
|
|
262
|
-
let targetProjectName;
|
|
263
|
-
if (dep.startsWith('project ')) {
|
|
264
|
-
targetProjectName = dep
|
|
265
|
-
.substring('project '.length)
|
|
266
|
-
.replace(/ \(n\)$/, '')
|
|
267
|
-
.trim()
|
|
268
|
-
.split(' ')?.[0];
|
|
269
|
-
}
|
|
270
|
-
else if (dep.includes('-> project')) {
|
|
271
|
-
const [_, projectName] = dep.split('-> project');
|
|
272
|
-
targetProjectName = projectName.trim().split(' ')?.[0];
|
|
273
|
-
}
|
|
274
|
-
if (targetProjectName) {
|
|
275
|
-
dependedProjects.add(targetProjectName);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
return dependedProjects;
|
|
281
|
-
}
|
|
@@ -28,7 +28,6 @@ async function getProjectReportLines(gradlewFile) {
|
|
|
28
28
|
try {
|
|
29
29
|
projectReportBuffer = await (0, exec_gradle_1.execGradleAsync)(gradlewFile, [
|
|
30
30
|
'projectReportAll',
|
|
31
|
-
process.env.NX_VERBOSE_LOGGING === 'true' ? '--info' : '',
|
|
32
31
|
]);
|
|
33
32
|
}
|
|
34
33
|
catch (e) {
|
|
@@ -65,15 +64,8 @@ async function getProjectReportLines(gradlewFile) {
|
|
|
65
64
|
], []);
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
|
-
|
|
67
|
+
return projectReportBuffer
|
|
69
68
|
.toString()
|
|
70
69
|
.split(exports.newLineSeparator)
|
|
71
70
|
.filter((line) => line.trim() !== '');
|
|
72
|
-
if (process.env.NX_VERBOSE_LOGGING === 'true') {
|
|
73
|
-
devkit_1.output.log({
|
|
74
|
-
title: `Successfully ran projectReportAll or projectRerport task using ${gradlewFile}`,
|
|
75
|
-
bodyLines: projectReportLines,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return projectReportLines;
|
|
79
71
|
}
|