@nx/gradle 21.0.0-beta.1 → 21.0.0-beta.11
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/batch-runner/project.json +33 -0
- package/executors.json +10 -0
- package/migrations.json +6 -0
- package/package.json +4 -2
- package/plugin-v1.d.ts +2 -0
- package/plugin-v1.js +8 -0
- package/plugin.d.ts +1 -1
- package/plugin.js +1 -2
- package/project-graph/project.json +43 -0
- package/project-graph/publish-maven.d.ts +1 -0
- package/project-graph/publish-maven.js +103 -0
- package/src/executors/gradle/gradle-batch.impl.d.ts +6 -0
- package/src/executors/gradle/gradle-batch.impl.js +67 -0
- package/src/executors/gradle/gradle.impl.d.ts +5 -0
- package/src/executors/gradle/gradle.impl.js +31 -0
- package/src/executors/gradle/schema.d.ts +5 -0
- package/src/executors/gradle/schema.json +33 -0
- package/src/generators/ci-workflow/files/circleci/.circleci/config.yml.template +1 -1
- package/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml.template +4 -3
- package/src/generators/init/init.js +28 -44
- package/src/migrations/19-4-0/add-project-report-all.d.ts +4 -0
- package/src/migrations/19-4-0/add-project-report-all.js +83 -2
- package/src/migrations/21-0-0/change-plugin-to-v1.d.ts +2 -0
- package/src/migrations/21-0-0/change-plugin-to-v1.js +26 -0
- package/src/plugin/dependencies.d.ts +2 -1
- package/src/plugin/dependencies.js +30 -53
- package/src/plugin/nodes.d.ts +3 -16
- package/src/plugin/nodes.js +22 -228
- package/src/plugin/utils/__mocks__/gradle_composite.json +38 -0
- package/src/plugin/utils/__mocks__/gradle_nx_list.json +590 -0
- package/src/plugin/utils/__mocks__/gradle_tutorial.json +344 -0
- package/src/plugin/utils/get-project-graph-from-gradle-plugin.d.ts +25 -0
- package/src/plugin/utils/get-project-graph-from-gradle-plugin.js +113 -0
- package/src/plugin/utils/get-project-graph-lines.d.ts +2 -0
- package/src/plugin/utils/get-project-graph-lines.js +66 -0
- package/src/plugin/utils/gradle-plugin-options.d.ts +7 -0
- package/src/plugin/utils/gradle-plugin-options.js +8 -0
- package/src/plugin-v1/dependencies.d.ts +2 -0
- package/src/plugin-v1/dependencies.js +64 -0
- package/src/plugin-v1/nodes.d.ts +20 -0
- package/src/plugin-v1/nodes.js +266 -0
- package/src/{utils → plugin-v1/utils}/get-gradle-report.d.ts +2 -2
- package/src/{utils → plugin-v1/utils}/get-gradle-report.js +23 -26
- package/src/{utils → plugin-v1/utils}/get-project-report-lines.d.ts +0 -2
- package/src/{utils → plugin-v1/utils}/get-project-report-lines.js +13 -18
- package/src/utils/exec-gradle.d.ts +5 -3
- package/src/utils/exec-gradle.js +12 -5
- package/src/utils/split-config-files.js +2 -0
- package/src/utils/versions.d.ts +2 -0
- package/src/utils/versions.js +3 -1
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gradle-batch-runner",
|
|
3
|
+
"$schema": "node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"projectRoot": "packages/gradle/batch-runner",
|
|
5
|
+
"sourceRoot": "packages/gradle/batch-runner/src",
|
|
6
|
+
"targets": {
|
|
7
|
+
"assemble": {
|
|
8
|
+
"command": "./gradlew :batch-runner:assemble",
|
|
9
|
+
"inputs": [
|
|
10
|
+
"{projectRoot}/src/**",
|
|
11
|
+
"{projectRoot}/build.gradle.kts",
|
|
12
|
+
"{projectRoot}/settings.gradle.kts"
|
|
13
|
+
],
|
|
14
|
+
"outputs": ["{projectRoot}/build"],
|
|
15
|
+
"cache": true
|
|
16
|
+
},
|
|
17
|
+
"test": {
|
|
18
|
+
"command": "./gradlew :batch-runner:test",
|
|
19
|
+
"options": {
|
|
20
|
+
"args": []
|
|
21
|
+
},
|
|
22
|
+
"cache": true
|
|
23
|
+
},
|
|
24
|
+
"lint": {
|
|
25
|
+
"command": "./gradlew :batch-runner:ktfmtCheck",
|
|
26
|
+
"cache": true
|
|
27
|
+
},
|
|
28
|
+
"format": {
|
|
29
|
+
"command": "./gradlew :batch-runner:ktfmtFormat",
|
|
30
|
+
"cache": true
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
package/executors.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"executors": {
|
|
3
|
+
"gradle": {
|
|
4
|
+
"batchImplementation": "./src/executors/gradle/gradle-batch.impl",
|
|
5
|
+
"implementation": "./src/executors/gradle/gradle.impl",
|
|
6
|
+
"schema": "./src/executors/gradle/schema.json",
|
|
7
|
+
"description": "The Gradlew executor is used to run Gradle tasks."
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
package/migrations.json
CHANGED
|
@@ -17,6 +17,12 @@
|
|
|
17
17
|
"cli": "nx",
|
|
18
18
|
"description": "Add includeSubprojectsTasks to build.gradle file",
|
|
19
19
|
"factory": "./src/migrations/20-2-0/add-include-subprojects-tasks"
|
|
20
|
+
},
|
|
21
|
+
"change-plugin-to-v1": {
|
|
22
|
+
"version": "21.0.0-beta.5",
|
|
23
|
+
"cli": "nx",
|
|
24
|
+
"description": "Change @nx/gradle plugin to version 1",
|
|
25
|
+
"factory": "./src/migrations/21-0-0/change-plugin-to-v1"
|
|
20
26
|
}
|
|
21
27
|
},
|
|
22
28
|
"packageJsonUpdates": {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/gradle",
|
|
3
|
-
"version": "21.0.0-beta.
|
|
3
|
+
"version": "21.0.0-beta.11",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for Gradle allows Gradle tasks to be run through Nx",
|
|
6
6
|
"repository": {
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"generators": "./generators.json",
|
|
27
27
|
"exports": {
|
|
28
28
|
".": "./index.js",
|
|
29
|
+
"./plugin-v1": "./plugin-v1.js",
|
|
29
30
|
"./package.json": "./package.json",
|
|
30
31
|
"./migrations.json": "./migrations.json",
|
|
31
32
|
"./generators.json": "./generators.json"
|
|
@@ -34,11 +35,12 @@
|
|
|
34
35
|
"migrations": "./migrations.json"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@nx/devkit": "21.0.0-beta.
|
|
38
|
+
"@nx/devkit": "21.0.0-beta.11"
|
|
38
39
|
},
|
|
39
40
|
"publishConfig": {
|
|
40
41
|
"access": "public"
|
|
41
42
|
},
|
|
43
|
+
"executors": "./executors.json",
|
|
42
44
|
"types": "./index.d.ts",
|
|
43
45
|
"type": "commonjs"
|
|
44
46
|
}
|
package/plugin-v1.d.ts
ADDED
package/plugin-v1.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNodesV2 = exports.createNodes = exports.createDependencies = void 0;
|
|
4
|
+
var dependencies_1 = require("./src/plugin-v1/dependencies");
|
|
5
|
+
Object.defineProperty(exports, "createDependencies", { enumerable: true, get: function () { return dependencies_1.createDependencies; } });
|
|
6
|
+
var nodes_1 = require("./src/plugin-v1/nodes");
|
|
7
|
+
Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return nodes_1.createNodes; } });
|
|
8
|
+
Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return nodes_1.createNodesV2; } });
|
package/plugin.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { createDependencies } from './src/plugin/dependencies';
|
|
2
|
-
export {
|
|
2
|
+
export { createNodesV2 } from './src/plugin/nodes';
|
package/plugin.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNodesV2 = exports.
|
|
3
|
+
exports.createNodesV2 = exports.createDependencies = void 0;
|
|
4
4
|
var dependencies_1 = require("./src/plugin/dependencies");
|
|
5
5
|
Object.defineProperty(exports, "createDependencies", { enumerable: true, get: function () { return dependencies_1.createDependencies; } });
|
|
6
6
|
var nodes_1 = require("./src/plugin/nodes");
|
|
7
|
-
Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return nodes_1.createNodes; } });
|
|
8
7
|
Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return nodes_1.createNodesV2; } });
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gradle-project-graph",
|
|
3
|
+
"$schema": "node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"targets": {
|
|
5
|
+
"test": {
|
|
6
|
+
"command": "./gradlew :project-graph:test",
|
|
7
|
+
"options": {
|
|
8
|
+
"args": []
|
|
9
|
+
},
|
|
10
|
+
"cache": true
|
|
11
|
+
},
|
|
12
|
+
"lint": {
|
|
13
|
+
"command": "./gradlew :project-graph:ktfmtCheck",
|
|
14
|
+
"cache": true
|
|
15
|
+
},
|
|
16
|
+
"format": {
|
|
17
|
+
"command": "./gradlew :project-graph:ktfmtFormat",
|
|
18
|
+
"cache": true
|
|
19
|
+
},
|
|
20
|
+
"publish-staging": {
|
|
21
|
+
"command": "./gradlew :project-graph:publish",
|
|
22
|
+
"cache": true,
|
|
23
|
+
"outputs": ["{projectRoot}/build/staging"]
|
|
24
|
+
},
|
|
25
|
+
"zip-staging": {
|
|
26
|
+
"command": "zip -r ../deployment.zip .",
|
|
27
|
+
"options": {
|
|
28
|
+
"cwd": "{projectRoot}/build/staging"
|
|
29
|
+
},
|
|
30
|
+
"inputs": ["{projectRoot}/build/staging"],
|
|
31
|
+
"outputs": ["{projectRoot}/build/deployment.zip"],
|
|
32
|
+
"dependsOn": ["publish-staging"]
|
|
33
|
+
},
|
|
34
|
+
"maven": {
|
|
35
|
+
"command": "npx ts-node publish-maven.ts --deploymentZipPath=build/deployment.zip",
|
|
36
|
+
"options": {
|
|
37
|
+
"cwd": "{projectRoot}"
|
|
38
|
+
},
|
|
39
|
+
"inputs": ["{projectRoot}/build/deployment.zip"],
|
|
40
|
+
"dependsOn": ["zip-staging"]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const axios_1 = require("axios");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const FormData = require("form-data");
|
|
6
|
+
function parseArgs() {
|
|
7
|
+
const args = process.argv.slice(2);
|
|
8
|
+
const result = {};
|
|
9
|
+
args.forEach((arg) => {
|
|
10
|
+
const [key, value] = arg.replace(/^--/, '').split('=');
|
|
11
|
+
result[key] = value;
|
|
12
|
+
});
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
async function publishToMavenApi(username, password, deploymentZipPath = 'deployment.zip') {
|
|
16
|
+
const token = Buffer.from(`${username}:${password}`).toString('base64');
|
|
17
|
+
console.log(`📦 Publishing to Maven Central...`);
|
|
18
|
+
const url = 'https://central.sonatype.com/api/v1/publisher/upload';
|
|
19
|
+
const form = new FormData();
|
|
20
|
+
form.append('bundle', fs.createReadStream(deploymentZipPath));
|
|
21
|
+
let uploadId;
|
|
22
|
+
try {
|
|
23
|
+
const response = await axios_1.default.post(url, form, {
|
|
24
|
+
headers: {
|
|
25
|
+
Authorization: `Basic ${token}`,
|
|
26
|
+
...form.getHeaders(),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
uploadId = response.data.toString().trim();
|
|
30
|
+
console.log(`✅ Upload ID: ${uploadId}`);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
console.error('🚫 Upload failed:', err.response?.data || err.message);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
let currentStatus = await getUploadStatus(uploadId, token);
|
|
37
|
+
if (['PENDING', 'VALIDATING', 'PUBLISHING'].includes(currentStatus)) {
|
|
38
|
+
currentStatus = await retryUntilValidatedOrPublished(currentStatus, uploadId, token);
|
|
39
|
+
}
|
|
40
|
+
if (!['VALIDATED', 'PUBLISHED'].includes(currentStatus)) {
|
|
41
|
+
console.error(`🚫 Upload failed with final status: ${currentStatus}`);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
console.log(`📦 Upload is ${currentStatus}, proceeding to deploy...`);
|
|
45
|
+
if (currentStatus === 'PUBLISHED') {
|
|
46
|
+
console.log('✅ Already published, skipping deployment.');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const deployUrl = `https://central.sonatype.com/api/v1/publisher/deployment/${uploadId}`;
|
|
50
|
+
try {
|
|
51
|
+
const deployRes = await axios_1.default.post(deployUrl, null, {
|
|
52
|
+
headers: { Authorization: `Basic ${token}` },
|
|
53
|
+
});
|
|
54
|
+
console.log(`🚀 Deployment response: ${deployRes.data}`);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
console.error('🚫 Deployment failed:', err.response?.data || err.message);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function getUploadStatus(uploadId, token) {
|
|
62
|
+
const url = `https://central.sonatype.com/api/v1/publisher/status?id=${uploadId}`;
|
|
63
|
+
try {
|
|
64
|
+
const response = await axios_1.default.post(url, null, {
|
|
65
|
+
headers: { Authorization: `Basic ${token}` },
|
|
66
|
+
});
|
|
67
|
+
const state = response.data.deploymentState;
|
|
68
|
+
console.log(`📡 Current deployment state: ${state}`);
|
|
69
|
+
return state;
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
console.error('🚫 Failed to get status:', err.response?.data || err.message);
|
|
73
|
+
return 'FAILED';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function retryUntilValidatedOrPublished(currentStatus, uploadId, token, retries = 10, delay = 10_000) {
|
|
77
|
+
for (let i = 0; i < retries; i++) {
|
|
78
|
+
console.log(`🔁 Checking status (attempt ${i + 1}/${retries})...`);
|
|
79
|
+
await sleep(delay);
|
|
80
|
+
currentStatus = await getUploadStatus(uploadId, token);
|
|
81
|
+
if (['VALIDATED', 'PUBLISHED', 'FAILED'].includes(currentStatus))
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
return currentStatus;
|
|
85
|
+
}
|
|
86
|
+
function sleep(ms) {
|
|
87
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
88
|
+
}
|
|
89
|
+
// Entry
|
|
90
|
+
(async function main() {
|
|
91
|
+
let { username, password, deploymentZipPath } = parseArgs();
|
|
92
|
+
username = username || process.env.MAVEN_USERNAME;
|
|
93
|
+
password = password || process.env.MAVEN_PASSWORD;
|
|
94
|
+
if (!username || !password) {
|
|
95
|
+
console.error('❌ Missing MAVEN_USERNAME or MAVEN_PASSWORD');
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
if (!deploymentZipPath) {
|
|
99
|
+
console.error('❌ Missing required --deploymentZipPath argument');
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
await publishToMavenApi(username, password, deploymentZipPath);
|
|
103
|
+
})();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ExecutorContext, TaskGraph } from '@nx/devkit';
|
|
2
|
+
import { RunCommandsOptions } from 'nx/src/executors/run-commands/run-commands.impl';
|
|
3
|
+
import { BatchResults } from 'nx/src/tasks-runner/batch/batch-messages';
|
|
4
|
+
import { gradleExecutorSchema } from './schema';
|
|
5
|
+
export declare const batchRunnerPath: string;
|
|
6
|
+
export default function gradleBatch(taskGraph: TaskGraph, inputs: Record<string, gradleExecutorSchema>, overrides: RunCommandsOptions, context: ExecutorContext): Promise<BatchResults>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.batchRunnerPath = void 0;
|
|
4
|
+
exports.default = gradleBatch;
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const run_commands_impl_1 = require("nx/src/executors/run-commands/run-commands.impl");
|
|
7
|
+
const exec_gradle_1 = require("../../utils/exec-gradle");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const child_process_1 = require("child_process");
|
|
10
|
+
exports.batchRunnerPath = (0, path_1.join)(__dirname, '../../../batch-runner/build/libs/batch-runner-all.jar');
|
|
11
|
+
async function gradleBatch(taskGraph, inputs, overrides, context) {
|
|
12
|
+
try {
|
|
13
|
+
const projectName = taskGraph.tasks[taskGraph.roots[0]]?.target?.project;
|
|
14
|
+
let projectRoot = context.projectGraph.nodes[projectName]?.data?.root ?? '';
|
|
15
|
+
const gradlewPath = (0, exec_gradle_1.findGradlewFile)((0, path_1.join)(projectRoot, 'project.json')); // find gradlew near project root
|
|
16
|
+
const root = (0, path_1.join)(context.root, (0, path_1.dirname)(gradlewPath));
|
|
17
|
+
// set args with passed in args and overrides in command line
|
|
18
|
+
const input = inputs[taskGraph.roots[0]];
|
|
19
|
+
let args = typeof input.args === 'string'
|
|
20
|
+
? input.args.trim().split(' ')
|
|
21
|
+
: Array.isArray(input.args)
|
|
22
|
+
? input.args
|
|
23
|
+
: [];
|
|
24
|
+
if (overrides.__overrides_unparsed__.length) {
|
|
25
|
+
args.push(...overrides.__overrides_unparsed__);
|
|
26
|
+
}
|
|
27
|
+
const gradlewTasksToRun = Object.entries(taskGraph.tasks).reduce((gradlewTasksToRun, [taskId, task]) => {
|
|
28
|
+
const gradlewTaskName = inputs[task.id].taskName;
|
|
29
|
+
const testClassName = inputs[task.id].testClassName;
|
|
30
|
+
gradlewTasksToRun[taskId] = {
|
|
31
|
+
taskName: gradlewTaskName,
|
|
32
|
+
testClassName: testClassName,
|
|
33
|
+
};
|
|
34
|
+
return gradlewTasksToRun;
|
|
35
|
+
}, {});
|
|
36
|
+
const gradlewBatchStart = performance.mark(`gradlew-batch:start`);
|
|
37
|
+
const batchResults = (0, child_process_1.execSync)(`java -jar ${exports.batchRunnerPath} --tasks='${JSON.stringify(gradlewTasksToRun)}' --workspaceRoot=${root} --args='${args
|
|
38
|
+
.join(' ')
|
|
39
|
+
.replaceAll("'", '"')}' ${process.env.NX_VERBOSE_LOGGING === 'true' ? '' : '--quiet'}`, {
|
|
40
|
+
windowsHide: true,
|
|
41
|
+
env: process.env,
|
|
42
|
+
maxBuffer: run_commands_impl_1.LARGE_BUFFER,
|
|
43
|
+
});
|
|
44
|
+
const gradlewBatchEnd = performance.mark(`gradlew-batch:end`);
|
|
45
|
+
performance.measure(`gradlew-batch`, gradlewBatchStart.name, gradlewBatchEnd.name);
|
|
46
|
+
const gradlewBatchResults = JSON.parse(batchResults.toString());
|
|
47
|
+
Object.keys(taskGraph.tasks).forEach((taskId) => {
|
|
48
|
+
if (!gradlewBatchResults[taskId]) {
|
|
49
|
+
gradlewBatchResults[taskId] = {
|
|
50
|
+
success: false,
|
|
51
|
+
terminalOutput: `Gradlew batch failed`,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return gradlewBatchResults;
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
devkit_1.output.error({
|
|
59
|
+
title: `Gradlew batch failed`,
|
|
60
|
+
bodyLines: [e.toString()],
|
|
61
|
+
});
|
|
62
|
+
return taskGraph.roots.reduce((acc, key) => {
|
|
63
|
+
acc[key] = { success: false, terminalOutput: e.toString() };
|
|
64
|
+
return acc;
|
|
65
|
+
}, {});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = gradleExecutor;
|
|
4
|
+
const exec_gradle_1 = require("../../utils/exec-gradle");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const run_commands_impl_1 = require("nx/src/executors/run-commands/run-commands.impl");
|
|
7
|
+
async function gradleExecutor(options, context) {
|
|
8
|
+
let projectRoot = context.projectGraph.nodes[context.projectName]?.data?.root ?? context.root;
|
|
9
|
+
let gradlewPath = (0, exec_gradle_1.findGradlewFile)((0, node_path_1.join)(projectRoot, 'project.json')); // find gradlew near project root
|
|
10
|
+
gradlewPath = (0, node_path_1.join)(context.root, gradlewPath);
|
|
11
|
+
let args = typeof options.args === 'string'
|
|
12
|
+
? options.args.trim().split(' ')
|
|
13
|
+
: Array.isArray(options.args)
|
|
14
|
+
? options.args
|
|
15
|
+
: [];
|
|
16
|
+
if (options.testClassName) {
|
|
17
|
+
args.push(`--tests`, options.testClassName);
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
await (0, run_commands_impl_1.default)({
|
|
21
|
+
command: `${gradlewPath} ${options.taskName}`,
|
|
22
|
+
cwd: (0, node_path_1.dirname)(gradlewPath),
|
|
23
|
+
args: args,
|
|
24
|
+
__unparsed__: [],
|
|
25
|
+
}, context);
|
|
26
|
+
return { success: true };
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
return { success: false };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"title": "Gradle Impl executor",
|
|
5
|
+
"description": "The Gradle Impl executor is used to run Gradle tasks.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"taskName": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The name of the Gradle task to run."
|
|
11
|
+
},
|
|
12
|
+
"testClassName": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The test class name to run for test task."
|
|
15
|
+
},
|
|
16
|
+
"args": {
|
|
17
|
+
"oneOf": [
|
|
18
|
+
{
|
|
19
|
+
"type": "array",
|
|
20
|
+
"items": {
|
|
21
|
+
"type": "string"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"type": "string"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"description": "The arguments to pass to the Gradle task.",
|
|
29
|
+
"examples": [["--warning-mode", "all"], "--stracktrace"]
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"required": ["taskName"]
|
|
33
|
+
}
|
package/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml.template
CHANGED
|
@@ -17,6 +17,7 @@ jobs:
|
|
|
17
17
|
- uses: actions/checkout@v4
|
|
18
18
|
with:
|
|
19
19
|
fetch-depth: 0
|
|
20
|
+
filter: tree:0
|
|
20
21
|
|
|
21
22
|
# This enables task distribution via Nx Cloud
|
|
22
23
|
# Run this command as early as possible, before dependencies are installed
|
|
@@ -24,15 +25,15 @@ jobs:
|
|
|
24
25
|
<% if (connectedToCloud) { %># Uncomment this line to enable task distribution<% } else { %># Connect your workspace by running "nx connect" and uncomment this line to enable task distribution<% } %>
|
|
25
26
|
# - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="3 linux-medium-jvm" --stop-agents-after="build"
|
|
26
27
|
|
|
27
|
-
- name: Set up JDK
|
|
28
|
+
- name: Set up JDK 21 for x64
|
|
28
29
|
uses: actions/setup-java@v4
|
|
29
30
|
with:
|
|
30
|
-
java-version: '
|
|
31
|
+
java-version: '21'
|
|
31
32
|
distribution: 'temurin'
|
|
32
33
|
architecture: x64
|
|
33
34
|
|
|
34
35
|
- name: Setup Gradle
|
|
35
|
-
uses: gradle/gradle-build-action@
|
|
36
|
+
uses: gradle/gradle-build-action@v4
|
|
36
37
|
|
|
37
38
|
- uses: nrwl/nx-set-shas@v4
|
|
38
39
|
|
|
@@ -32,7 +32,6 @@ function addPlugin(tree) {
|
|
|
32
32
|
testTargetName: 'test',
|
|
33
33
|
classesTargetName: 'classes',
|
|
34
34
|
buildTargetName: 'build',
|
|
35
|
-
includeSubprojectsTasks: false,
|
|
36
35
|
},
|
|
37
36
|
});
|
|
38
37
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
@@ -46,15 +45,14 @@ async function addBuildGradleFileNextToSettingsGradle(tree) {
|
|
|
46
45
|
'**/settings.gradle?(.kts)',
|
|
47
46
|
]);
|
|
48
47
|
settingsGradleFiles.forEach((settingsGradleFile) => {
|
|
49
|
-
|
|
48
|
+
addNxProjectGraphPluginToBuildGradle(settingsGradleFile, tree);
|
|
50
49
|
});
|
|
51
50
|
}
|
|
52
51
|
/**
|
|
53
52
|
* - creates a build.gradle file next to the settings.gradle file if it does not exist.
|
|
54
|
-
* - adds the
|
|
55
|
-
* - adds a task to generate project reports for all subprojects and included builds.
|
|
53
|
+
* - adds the NxProjectGraphPlugin plugin to the build.gradle file if it does not exist.
|
|
56
54
|
*/
|
|
57
|
-
function
|
|
55
|
+
function addNxProjectGraphPluginToBuildGradle(settingsGradleFile, tree) {
|
|
58
56
|
const filename = (0, path_1.basename)(settingsGradleFile);
|
|
59
57
|
let gradleFilePath = 'build.gradle';
|
|
60
58
|
if (filename.endsWith('.kts')) {
|
|
@@ -68,54 +66,40 @@ function addProjectReportToBuildGradle(settingsGradleFile, tree) {
|
|
|
68
66
|
else {
|
|
69
67
|
buildGradleContent = tree.read(gradleFilePath).toString();
|
|
70
68
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
const nxProjectGraphReportPlugin = filename.endsWith('.kts')
|
|
70
|
+
? `id("${versions_1.gradleProjectGraphPluginName}") version("${versions_1.gradleProjectGraphVersion}")`
|
|
71
|
+
: `id "${versions_1.gradleProjectGraphPluginName}" version "${versions_1.gradleProjectGraphVersion}"`;
|
|
72
|
+
if (buildGradleContent.includes('plugins {')) {
|
|
73
|
+
if (!buildGradleContent.includes(versions_1.gradleProjectGraphPluginName)) {
|
|
74
|
+
buildGradleContent = buildGradleContent.replace('plugins {', `plugins {
|
|
75
|
+
${nxProjectGraphReportPlugin}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
buildGradleContent = `plugins {
|
|
80
|
+
${nxProjectGraphReportPlugin}
|
|
81
|
+
}\n\r${buildGradleContent}`;
|
|
82
|
+
}
|
|
83
|
+
const applyNxProjectGraphReportPlugin = `plugin("${versions_1.gradleProjectGraphPluginName}")`;
|
|
84
|
+
if (buildGradleContent.includes('allprojects {')) {
|
|
85
|
+
if (!buildGradleContent.includes(`plugin("${versions_1.gradleProjectGraphPluginName}")`) &&
|
|
86
|
+
!buildGradleContent.includes(`plugin('${versions_1.gradleProjectGraphPluginName}')`)) {
|
|
87
|
+
devkit_1.logger.warn(`Please add the ${versions_1.gradleProjectGraphPluginName} plugin to your ${gradleFilePath}:
|
|
74
88
|
allprojects {
|
|
75
89
|
apply {
|
|
76
|
-
|
|
90
|
+
${applyNxProjectGraphReportPlugin}
|
|
77
91
|
}
|
|
78
92
|
}`);
|
|
79
93
|
}
|
|
80
94
|
}
|
|
81
95
|
else {
|
|
82
|
-
buildGradleContent
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
}`;
|
|
87
|
-
}
|
|
88
|
-
if (!buildGradleContent.includes(`tasks.register("projectReportAll")`)) {
|
|
89
|
-
if (gradleFilePath.endsWith('.kts')) {
|
|
90
|
-
buildGradleContent += `\n\rtasks.register("projectReportAll") {
|
|
91
|
-
// All project reports of subprojects
|
|
92
|
-
allprojects.forEach {
|
|
93
|
-
dependsOn(it.tasks.get("projectReport"))
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// All projectReportAll of included builds
|
|
97
|
-
gradle.includedBuilds.forEach {
|
|
98
|
-
dependsOn(it.task(":projectReportAll"))
|
|
99
|
-
}
|
|
100
|
-
}`;
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
buildGradleContent += `\n\rtasks.register("projectReportAll") {
|
|
104
|
-
// All project reports of subprojects
|
|
105
|
-
allprojects.forEach {
|
|
106
|
-
dependsOn(it.tasks.getAt("projectReport"))
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// All projectReportAll of included builds
|
|
110
|
-
gradle.includedBuilds.forEach {
|
|
111
|
-
dependsOn(it.task(":projectReportAll"))
|
|
112
|
-
}
|
|
113
|
-
}`;
|
|
114
|
-
}
|
|
96
|
+
buildGradleContent = `${buildGradleContent}\n\rallprojects {
|
|
97
|
+
apply {
|
|
98
|
+
${applyNxProjectGraphReportPlugin}
|
|
115
99
|
}
|
|
116
|
-
|
|
117
|
-
tree.write(gradleFilePath, buildGradleContent);
|
|
100
|
+
}`;
|
|
118
101
|
}
|
|
102
|
+
tree.write(gradleFilePath, buildGradleContent);
|
|
119
103
|
}
|
|
120
104
|
function updateNxJsonConfiguration(tree) {
|
|
121
105
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
@@ -3,3 +3,7 @@ import { Tree } from '@nx/devkit';
|
|
|
3
3
|
* This migration adds task `projectReportAll` to build.gradle files
|
|
4
4
|
*/
|
|
5
5
|
export default function update(tree: Tree): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* This function creates and populate build.gradle file next to the settings.gradle file.
|
|
8
|
+
*/
|
|
9
|
+
export declare function addBuildGradleFileNextToSettingsGradle(tree: Tree): Promise<void>;
|