@nx/gradle 21.2.0-beta.3 → 21.2.0-beta.5
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/batch-runner/build/libs/batch-runner-all.jar +0 -0
- package/batch-runner/build/libs/batch-runner.jar +0 -0
- package/package.json +2 -2
- package/src/executors/gradle/get-exclude-task.d.ts +4 -7
- package/src/executors/gradle/get-exclude-task.js +30 -21
- package/src/executors/gradle/gradle-batch.impl.d.ts +9 -1
- package/src/executors/gradle/gradle-batch.impl.js +55 -37
- package/src/executors/gradle/gradle.impl.js +1 -7
- package/src/executors/gradle/schema.json +1 -1
Binary file
|
Binary file
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/gradle",
|
3
|
-
"version": "21.2.0-beta.
|
3
|
+
"version": "21.2.0-beta.5",
|
4
4
|
"private": false,
|
5
5
|
"description": "The Nx Plugin for Gradle allows Gradle tasks to be run through Nx",
|
6
6
|
"repository": {
|
@@ -35,7 +35,7 @@
|
|
35
35
|
"migrations": "./migrations.json"
|
36
36
|
},
|
37
37
|
"dependencies": {
|
38
|
-
"@nx/devkit": "21.2.0-beta.
|
38
|
+
"@nx/devkit": "21.2.0-beta.5"
|
39
39
|
},
|
40
40
|
"publishConfig": {
|
41
41
|
"access": "public"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { ProjectGraphProjectNode } from 'nx/src/config/project-graph';
|
2
2
|
/**
|
3
3
|
* Returns Gradle CLI arguments to exclude dependent tasks
|
4
4
|
* that are not part of the current execution set.
|
@@ -6,9 +6,6 @@ import { ProjectGraph } from 'nx/src/config/project-graph';
|
|
6
6
|
* For example, if a project defines `dependsOn: ['lint']` for the `test` target,
|
7
7
|
* and only `test` is running, this will return: ['lint']
|
8
8
|
*/
|
9
|
-
export declare function getExcludeTasks(
|
10
|
-
|
11
|
-
|
12
|
-
excludeDependsOn: boolean;
|
13
|
-
}[], runningTaskIds?: Set<string>): Set<string>;
|
14
|
-
export declare function getAllDependsOn(projectGraph: ProjectGraph, projectName: string, targetName: string, visited?: Set<string>): string[];
|
9
|
+
export declare function getExcludeTasks(taskIds: Set<string>, nodes: Record<string, ProjectGraphProjectNode>, runningTaskIds?: Set<string>): Set<string>;
|
10
|
+
export declare function getGradleTaskNameWithNxTaskId(nxTaskId: string, nodes: Record<string, ProjectGraphProjectNode>): string | null;
|
11
|
+
export declare function getAllDependsOn(nodes: Record<string, ProjectGraphProjectNode>, projectName: string, targetName: string): Set<string>;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.getExcludeTasks = getExcludeTasks;
|
4
|
+
exports.getGradleTaskNameWithNxTaskId = getGradleTaskNameWithNxTaskId;
|
4
5
|
exports.getAllDependsOn = getAllDependsOn;
|
5
6
|
/**
|
6
7
|
* Returns Gradle CLI arguments to exclude dependent tasks
|
@@ -9,38 +10,46 @@ exports.getAllDependsOn = getAllDependsOn;
|
|
9
10
|
* For example, if a project defines `dependsOn: ['lint']` for the `test` target,
|
10
11
|
* and only `test` is running, this will return: ['lint']
|
11
12
|
*/
|
12
|
-
function getExcludeTasks(
|
13
|
+
function getExcludeTasks(taskIds, nodes, runningTaskIds = new Set()) {
|
13
14
|
const excludes = new Set();
|
14
|
-
for (const
|
15
|
-
|
16
|
-
|
17
|
-
}
|
18
|
-
const taskDeps = projectGraph.nodes[project]?.data?.targets?.[target]?.dependsOn ?? [];
|
15
|
+
for (const taskId of taskIds) {
|
16
|
+
const [project, target] = taskId.split(':');
|
17
|
+
const taskDeps = nodes[project]?.data?.targets?.[target]?.dependsOn ?? [];
|
19
18
|
for (const dep of taskDeps) {
|
20
19
|
const taskId = typeof dep === 'string' ? dep : dep?.target;
|
21
20
|
if (taskId && !runningTaskIds.has(taskId)) {
|
22
|
-
const
|
23
|
-
|
24
|
-
|
25
|
-
if (taskName) {
|
26
|
-
excludes.add(taskName);
|
21
|
+
const gradleTaskName = getGradleTaskNameWithNxTaskId(taskId, nodes);
|
22
|
+
if (gradleTaskName) {
|
23
|
+
excludes.add(gradleTaskName);
|
27
24
|
}
|
28
25
|
}
|
29
26
|
}
|
30
27
|
}
|
31
28
|
return excludes;
|
32
29
|
}
|
33
|
-
function
|
34
|
-
const
|
35
|
-
const
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
30
|
+
function getGradleTaskNameWithNxTaskId(nxTaskId, nodes) {
|
31
|
+
const [projectName, targetName] = nxTaskId.split(':');
|
32
|
+
const gradleTaskName = nodes[projectName]?.data?.targets?.[targetName]?.options?.taskName;
|
33
|
+
return gradleTaskName;
|
34
|
+
}
|
35
|
+
function getAllDependsOn(nodes, projectName, targetName) {
|
36
|
+
const allDependsOn = new Set();
|
37
|
+
const stack = [`${projectName}:${targetName}`];
|
38
|
+
while (stack.length > 0) {
|
39
|
+
const currentTaskId = stack.pop();
|
40
|
+
if (currentTaskId && !allDependsOn.has(currentTaskId)) {
|
41
|
+
allDependsOn.add(currentTaskId);
|
42
|
+
const [currentProjectName, currentTargetName] = currentTaskId.split(':');
|
43
|
+
const directDependencies = nodes[currentProjectName]?.data?.targets?.[currentTargetName]
|
44
|
+
?.dependsOn ?? [];
|
45
|
+
for (const dep of directDependencies) {
|
46
|
+
const depTaskId = typeof dep === 'string' ? dep : dep?.target;
|
47
|
+
if (depTaskId && !allDependsOn.has(depTaskId)) {
|
48
|
+
stack.push(depTaskId);
|
49
|
+
}
|
50
|
+
}
|
43
51
|
}
|
44
52
|
}
|
53
|
+
allDependsOn.delete(`${projectName}:${targetName}`); // Exclude the starting task itself
|
45
54
|
return allDependsOn;
|
46
55
|
}
|
@@ -1,6 +1,14 @@
|
|
1
|
-
import { ExecutorContext, TaskGraph } from '@nx/devkit';
|
1
|
+
import { ExecutorContext, ProjectGraphProjectNode, TaskGraph } from '@nx/devkit';
|
2
2
|
import { RunCommandsOptions } from 'nx/src/executors/run-commands/run-commands.impl';
|
3
3
|
import { BatchResults } from 'nx/src/tasks-runner/batch/batch-messages';
|
4
4
|
import { GradleExecutorSchema } from './schema';
|
5
5
|
export declare const batchRunnerPath: string;
|
6
6
|
export default function gradleBatch(taskGraph: TaskGraph, inputs: Record<string, GradleExecutorSchema>, overrides: RunCommandsOptions, context: ExecutorContext): Promise<BatchResults>;
|
7
|
+
/**
|
8
|
+
* Get the gradlew task ids to run
|
9
|
+
*/
|
10
|
+
export declare function getGradlewTasksToRun(taskIds: string[], taskGraph: TaskGraph, inputs: Record<string, GradleExecutorSchema>, nodes: Record<string, ProjectGraphProjectNode>): {
|
11
|
+
gradlewTasksToRun: Record<string, GradleExecutorSchema>;
|
12
|
+
excludeTasks: Set<string>;
|
13
|
+
excludeTestTasks: Set<string>;
|
14
|
+
};
|
@@ -2,6 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.batchRunnerPath = void 0;
|
4
4
|
exports.default = gradleBatch;
|
5
|
+
exports.getGradlewTasksToRun = getGradlewTasksToRun;
|
5
6
|
const devkit_1 = require("@nx/devkit");
|
6
7
|
const run_commands_impl_1 = require("nx/src/executors/run-commands/run-commands.impl");
|
7
8
|
const exec_gradle_1 = require("../../utils/exec-gradle");
|
@@ -27,42 +28,9 @@ async function gradleBatch(taskGraph, inputs, overrides, context) {
|
|
27
28
|
if (overrides.__overrides_unparsed__.length) {
|
28
29
|
args.push(...overrides.__overrides_unparsed__);
|
29
30
|
}
|
30
|
-
const taskIdsWithExclude = [];
|
31
|
-
const taskIdsWithoutExclude = [];
|
32
31
|
const taskIds = Object.keys(taskGraph.tasks);
|
33
|
-
|
34
|
-
|
35
|
-
taskIdsWithExclude.push(taskId);
|
36
|
-
}
|
37
|
-
else {
|
38
|
-
taskIdsWithoutExclude.push(taskId);
|
39
|
-
}
|
40
|
-
}
|
41
|
-
const allDependsOn = new Set(taskIds);
|
42
|
-
taskIdsWithoutExclude.forEach((taskId) => {
|
43
|
-
const [projectName, targetName] = taskId.split(':');
|
44
|
-
const dependencies = (0, get_exclude_task_1.getAllDependsOn)(context.projectGraph, projectName, targetName);
|
45
|
-
dependencies.forEach((dep) => allDependsOn.add(dep));
|
46
|
-
});
|
47
|
-
const gradlewTasksToRun = taskIds.reduce((gradlewTasksToRun, taskId) => {
|
48
|
-
const task = taskGraph.tasks[taskId];
|
49
|
-
const gradlewTaskName = inputs[task.id].taskName;
|
50
|
-
const testClassName = inputs[task.id].testClassName;
|
51
|
-
gradlewTasksToRun[taskId] = {
|
52
|
-
taskName: gradlewTaskName,
|
53
|
-
testClassName: testClassName,
|
54
|
-
};
|
55
|
-
return gradlewTasksToRun;
|
56
|
-
}, {});
|
57
|
-
const excludeTasks = (0, get_exclude_task_1.getExcludeTasks)(context.projectGraph, taskIdsWithExclude.map((taskId) => {
|
58
|
-
const task = taskGraph.tasks[taskId];
|
59
|
-
return {
|
60
|
-
project: task?.target?.project,
|
61
|
-
target: task?.target?.target,
|
62
|
-
excludeDependsOn: inputs[taskId]?.excludeDependsOn,
|
63
|
-
};
|
64
|
-
}), allDependsOn);
|
65
|
-
const batchResults = await runTasksInBatch(gradlewTasksToRun, excludeTasks, args, root);
|
32
|
+
const { gradlewTasksToRun, excludeTasks, excludeTestTasks } = getGradlewTasksToRun(taskIds, taskGraph, inputs, context.projectGraph.nodes);
|
33
|
+
const batchResults = await runTasksInBatch(gradlewTasksToRun, excludeTasks, excludeTestTasks, args, root);
|
66
34
|
taskIds.forEach((taskId) => {
|
67
35
|
if (!batchResults[taskId]) {
|
68
36
|
batchResults[taskId] = {
|
@@ -84,13 +52,63 @@ async function gradleBatch(taskGraph, inputs, overrides, context) {
|
|
84
52
|
}, {});
|
85
53
|
}
|
86
54
|
}
|
87
|
-
|
55
|
+
/**
|
56
|
+
* Get the gradlew task ids to run
|
57
|
+
*/
|
58
|
+
function getGradlewTasksToRun(taskIds, taskGraph, inputs, nodes) {
|
59
|
+
const taskIdsWithExclude = new Set([]);
|
60
|
+
const testTaskIdsWithExclude = new Set([]);
|
61
|
+
const taskIdsWithoutExclude = new Set([]);
|
62
|
+
const gradlewTasksToRun = {};
|
63
|
+
for (const taskId of taskIds) {
|
64
|
+
const task = taskGraph.tasks[taskId];
|
65
|
+
const input = inputs[task.id];
|
66
|
+
gradlewTasksToRun[taskId] = input;
|
67
|
+
if (input.excludeDependsOn) {
|
68
|
+
if (input.testClassName) {
|
69
|
+
testTaskIdsWithExclude.add(taskId);
|
70
|
+
}
|
71
|
+
else {
|
72
|
+
taskIdsWithExclude.add(taskId);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
else {
|
76
|
+
taskIdsWithoutExclude.add(taskId);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
const allDependsOn = new Set(taskIds);
|
80
|
+
for (const taskId of taskIdsWithoutExclude) {
|
81
|
+
const [projectName, targetName] = taskId.split(':');
|
82
|
+
const dependencies = (0, get_exclude_task_1.getAllDependsOn)(nodes, projectName, targetName);
|
83
|
+
dependencies.forEach((dep) => allDependsOn.add(dep));
|
84
|
+
}
|
85
|
+
const excludeTasks = (0, get_exclude_task_1.getExcludeTasks)(taskIdsWithExclude, nodes, allDependsOn);
|
86
|
+
const allTestsDependsOn = new Set();
|
87
|
+
for (const taskId of testTaskIdsWithExclude) {
|
88
|
+
const [projectName, targetName] = taskId.split(':');
|
89
|
+
const taskDependsOn = (0, get_exclude_task_1.getAllDependsOn)(nodes, projectName, targetName);
|
90
|
+
taskDependsOn.forEach((dep) => allTestsDependsOn.add(dep));
|
91
|
+
}
|
92
|
+
const excludeTestTasks = new Set();
|
93
|
+
for (let taskId of allTestsDependsOn) {
|
94
|
+
const gradleTaskName = (0, get_exclude_task_1.getGradleTaskNameWithNxTaskId)(taskId, nodes);
|
95
|
+
if (gradleTaskName) {
|
96
|
+
excludeTestTasks.add(gradleTaskName);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
return {
|
100
|
+
gradlewTasksToRun,
|
101
|
+
excludeTasks,
|
102
|
+
excludeTestTasks,
|
103
|
+
};
|
104
|
+
}
|
105
|
+
async function runTasksInBatch(gradlewTasksToRun, excludeTasks, excludeTestTasks, args, root) {
|
88
106
|
const gradlewBatchStart = performance.mark(`gradlew-batch:start`);
|
89
107
|
const usePseudoTerminal = process.env.NX_NATIVE_COMMAND_RUNNER !== 'false' &&
|
90
108
|
pseudo_terminal_1.PseudoTerminal.isSupported();
|
91
109
|
const command = `java -jar ${exports.batchRunnerPath} --tasks='${JSON.stringify(gradlewTasksToRun)}' --workspaceRoot=${root} --args='${args
|
92
110
|
.join(' ')
|
93
|
-
.replaceAll("'", '"')}' --excludeTasks='${Array.from(excludeTasks).join(',')}' ${process.env.NX_VERBOSE_LOGGING === 'true' ? '' : '--quiet'}`;
|
111
|
+
.replaceAll("'", '"')}' --excludeTasks='${Array.from(excludeTasks).join(',')}' --excludeTestTasks='${Array.from(excludeTestTasks).join(',')}' ${process.env.NX_VERBOSE_LOGGING === 'true' ? '' : '--quiet'}`;
|
94
112
|
let batchResults;
|
95
113
|
if (usePseudoTerminal && process.env.NX_VERBOSE_LOGGING !== 'true') {
|
96
114
|
const terminal = (0, pseudo_terminal_1.createPseudoTerminal)();
|
@@ -17,13 +17,7 @@ async function gradleExecutor(options, context) {
|
|
17
17
|
if (options.testClassName) {
|
18
18
|
args.push(`--tests`, options.testClassName);
|
19
19
|
}
|
20
|
-
(0, get_exclude_task_1.getExcludeTasks)(context.
|
21
|
-
{
|
22
|
-
project: context.projectName,
|
23
|
-
target: context.targetName,
|
24
|
-
excludeDependsOn: options.excludeDependsOn,
|
25
|
-
},
|
26
|
-
]).forEach((task) => {
|
20
|
+
(0, get_exclude_task_1.getExcludeTasks)(new Set([`${context.projectName}:${context.targetName}`]), context.projectGraph.nodes).forEach((task) => {
|
27
21
|
if (task) {
|
28
22
|
args.push('--exclude-task', task);
|
29
23
|
}
|