@nx/gradle 21.0.0-canary.20250423-16fc551 → 21.0.0-canary.20250425-ee097a8
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/executors.json +3 -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/generators/ci-workflow/files/circleci/.circleci/config.yml.template +1 -1
- package/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml.template +3 -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 -55
- package/src/plugin/nodes.d.ts +3 -16
- package/src/plugin/nodes.js +17 -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 +6 -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 +20 -24
- 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 +2 -10
- 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
package/executors.json
ADDED
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-canary.
|
3
|
+
"version": "21.0.0-canary.20250425-ee097a8",
|
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-canary.
|
38
|
+
"@nx/devkit": "21.0.0-canary.20250425-ee097a8"
|
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
|
+
})();
|
package/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml.template
CHANGED
@@ -25,15 +25,15 @@ jobs:
|
|
25
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<% } %>
|
26
26
|
# - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="3 linux-medium-jvm" --stop-agents-after="build"
|
27
27
|
|
28
|
-
- name: Set up JDK
|
28
|
+
- name: Set up JDK 21 for x64
|
29
29
|
uses: actions/setup-java@v4
|
30
30
|
with:
|
31
|
-
java-version: '
|
31
|
+
java-version: '21'
|
32
32
|
distribution: 'temurin'
|
33
33
|
architecture: x64
|
34
34
|
|
35
35
|
- name: Setup Gradle
|
36
|
-
uses: gradle/gradle-build-action@
|
36
|
+
uses: gradle/gradle-build-action@v4
|
37
37
|
|
38
38
|
- uses: nrwl/nx-set-shas@v4
|
39
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>;
|
@@ -1,10 +1,91 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.default = update;
|
4
|
-
|
4
|
+
exports.addBuildGradleFileNextToSettingsGradle = addBuildGradleFileNextToSettingsGradle;
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
6
|
+
const node_path_1 = require("node:path");
|
5
7
|
/**
|
6
8
|
* This migration adds task `projectReportAll` to build.gradle files
|
7
9
|
*/
|
8
10
|
async function update(tree) {
|
9
|
-
await
|
11
|
+
await addBuildGradleFileNextToSettingsGradle(tree);
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
* This function creates and populate build.gradle file next to the settings.gradle file.
|
15
|
+
*/
|
16
|
+
async function addBuildGradleFileNextToSettingsGradle(tree) {
|
17
|
+
const settingsGradleFiles = await (0, devkit_1.globAsync)(tree, [
|
18
|
+
'**/settings.gradle?(.kts)',
|
19
|
+
]);
|
20
|
+
settingsGradleFiles.forEach((settingsGradleFile) => {
|
21
|
+
addProjectReportToBuildGradle(settingsGradleFile, tree);
|
22
|
+
});
|
23
|
+
}
|
24
|
+
/**
|
25
|
+
* - creates a build.gradle file next to the settings.gradle file if it does not exist.
|
26
|
+
* - adds the project-report plugin to the build.gradle file if it does not exist.
|
27
|
+
* - adds a task to generate project reports for all subprojects and included builds.
|
28
|
+
*/
|
29
|
+
function addProjectReportToBuildGradle(settingsGradleFile, tree) {
|
30
|
+
const filename = (0, node_path_1.basename)(settingsGradleFile);
|
31
|
+
let gradleFilePath = 'build.gradle';
|
32
|
+
if (filename.endsWith('.kts')) {
|
33
|
+
gradleFilePath = 'build.gradle.kts';
|
34
|
+
}
|
35
|
+
gradleFilePath = (0, node_path_1.join)((0, node_path_1.dirname)(settingsGradleFile), gradleFilePath);
|
36
|
+
let buildGradleContent = '';
|
37
|
+
if (!tree.exists(gradleFilePath)) {
|
38
|
+
tree.write(gradleFilePath, buildGradleContent); // create a build.gradle file near settings.gradle file if it does not exist
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
buildGradleContent = tree.read(gradleFilePath).toString();
|
42
|
+
}
|
43
|
+
if (buildGradleContent.includes('allprojects')) {
|
44
|
+
if (!buildGradleContent.includes('"project-report"')) {
|
45
|
+
devkit_1.logger.warn(`Please add the project-report plugin to your ${gradleFilePath}:
|
46
|
+
allprojects {
|
47
|
+
apply {
|
48
|
+
plugin("project-report")
|
49
|
+
}
|
50
|
+
}`);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
else {
|
54
|
+
buildGradleContent += `\n\rallprojects {
|
55
|
+
apply {
|
56
|
+
plugin("project-report")
|
57
|
+
}
|
58
|
+
}`;
|
59
|
+
}
|
60
|
+
if (!buildGradleContent.includes(`tasks.register("projectReportAll")`)) {
|
61
|
+
if (gradleFilePath.endsWith('.kts')) {
|
62
|
+
buildGradleContent += `\n\rtasks.register("projectReportAll") {
|
63
|
+
// All project reports of subprojects
|
64
|
+
allprojects.forEach {
|
65
|
+
dependsOn(it.tasks.get("projectReport"))
|
66
|
+
}
|
67
|
+
|
68
|
+
// All projectReportAll of included builds
|
69
|
+
gradle.includedBuilds.forEach {
|
70
|
+
dependsOn(it.task(":projectReportAll"))
|
71
|
+
}
|
72
|
+
}`;
|
73
|
+
}
|
74
|
+
else {
|
75
|
+
buildGradleContent += `\n\rtasks.register("projectReportAll") {
|
76
|
+
// All project reports of subprojects
|
77
|
+
allprojects.forEach {
|
78
|
+
dependsOn(it.tasks.getAt("projectReport"))
|
79
|
+
}
|
80
|
+
|
81
|
+
// All projectReportAll of included builds
|
82
|
+
gradle.includedBuilds.forEach {
|
83
|
+
dependsOn(it.task(":projectReportAll"))
|
84
|
+
}
|
85
|
+
}`;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
if (buildGradleContent) {
|
89
|
+
tree.write(gradleFilePath, buildGradleContent);
|
90
|
+
}
|
10
91
|
}
|
@@ -0,0 +1,26 @@
|
|
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 changes the plugin to v1
|
7
|
+
* Replace @nx/gradle with @nx/gradle/plugin-v1
|
8
|
+
*/
|
9
|
+
function update(tree) {
|
10
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
11
|
+
if (!nxJson) {
|
12
|
+
return;
|
13
|
+
}
|
14
|
+
if (!(0, has_gradle_plugin_1.hasGradlePlugin)(tree)) {
|
15
|
+
return;
|
16
|
+
}
|
17
|
+
let gradlePluginIndex = nxJson.plugins.findIndex((p) => typeof p === 'string' ? p === '@nx/gradle' : p.plugin === '@nx/gradle');
|
18
|
+
let gradlePlugin = nxJson.plugins[gradlePluginIndex];
|
19
|
+
if (typeof gradlePlugin === 'string') {
|
20
|
+
nxJson.plugins[gradlePluginIndex] = '@nx/gradle/plugin-v1';
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
gradlePlugin.plugin = '@nx/gradle/plugin-v1';
|
24
|
+
}
|
25
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
26
|
+
}
|
@@ -3,62 +3,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createDependencies = void 0;
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
5
|
const node_path_1 = require("node:path");
|
6
|
-
const
|
6
|
+
const get_project_graph_from_gradle_plugin_1 = require("./utils/get-project-graph-from-gradle-plugin");
|
7
7
|
const split_config_files_1 = require("../utils/split-config-files");
|
8
|
-
const
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
const
|
14
|
-
const
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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);
|
8
|
+
const workspace_context_1 = require("nx/src/utils/workspace-context");
|
9
|
+
const createDependencies = async (options, context) => {
|
10
|
+
const files = await (0, workspace_context_1.globWithWorkspaceContext)(devkit_1.workspaceRoot, Array.from(split_config_files_1.GRALDEW_FILES));
|
11
|
+
const { gradlewFiles } = (0, split_config_files_1.splitConfigFiles)(files);
|
12
|
+
await (0, get_project_graph_from_gradle_plugin_1.populateProjectGraph)(context.workspaceRoot, gradlewFiles, options);
|
13
|
+
const { dependencies: dependenciesFromReport } = (0, get_project_graph_from_gradle_plugin_1.getCurrentProjectGraphReport)();
|
14
|
+
const dependencies = [];
|
15
|
+
dependenciesFromReport.forEach((dependencyFromPlugin) => {
|
16
|
+
try {
|
17
|
+
const source = (0, node_path_1.relative)(devkit_1.workspaceRoot, dependencyFromPlugin.source) || '.';
|
18
|
+
const sourceProjectName = Object.values(context.projects).find((project) => source === project.root)?.name ?? dependencyFromPlugin.source;
|
19
|
+
const target = (0, node_path_1.relative)(devkit_1.workspaceRoot, dependencyFromPlugin.target) || '.';
|
20
|
+
const targetProjectName = Object.values(context.projects).find((project) => target === project.root)?.name ?? dependencyFromPlugin.target;
|
21
|
+
if (!sourceProjectName || !targetProjectName) {
|
22
|
+
return;
|
46
23
|
}
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
24
|
+
const dependency = {
|
25
|
+
source: sourceProjectName,
|
26
|
+
target: targetProjectName,
|
27
|
+
type: devkit_1.DependencyType.static,
|
28
|
+
sourceFile: (0, devkit_1.normalizePath)((0, node_path_1.relative)(devkit_1.workspaceRoot, dependencyFromPlugin.sourceFile)),
|
29
|
+
};
|
30
|
+
(0, devkit_1.validateDependency)(dependency, context);
|
31
|
+
dependencies.push(dependency);
|
32
|
+
}
|
33
|
+
catch {
|
34
|
+
devkit_1.logger.warn(`Unable to parse dependency from gradle plugin: ${dependencyFromPlugin.source} -> ${dependencyFromPlugin.target}`);
|
35
|
+
}
|
36
|
+
});
|
37
|
+
return dependencies;
|
52
38
|
};
|
53
39
|
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
|
-
}
|
package/src/plugin/nodes.d.ts
CHANGED
@@ -1,20 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
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
|
-
}
|
1
|
+
import { CreateNodesV2, ProjectConfiguration, CreateNodesFunction, ProjectGraphExternalNode } from '@nx/devkit';
|
2
|
+
import { GradlePluginOptions } from './utils/gradle-plugin-options';
|
11
3
|
type GradleTargets = Record<string, Partial<ProjectConfiguration>>;
|
12
4
|
export declare function writeTargetsToCache(cachePath: string, results: GradleTargets): void;
|
13
5
|
export declare const createNodesV2: CreateNodesV2<GradlePluginOptions>;
|
14
|
-
export declare const makeCreateNodesForGradleConfigFile: (
|
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>;
|
6
|
+
export declare const makeCreateNodesForGradleConfigFile: (projects: Record<string, Partial<ProjectConfiguration>>, projectsCache?: GradleTargets, externalNodes?: Record<string, ProjectGraphExternalNode>) => CreateNodesFunction;
|
20
7
|
export {};
|