@nx/gradle 18.2.0-beta.0
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/LICENSE +22 -0
- package/README.md +68 -0
- package/generators.json +11 -0
- package/index.d.ts +1 -0
- package/index.js +4 -0
- package/migrations.json +4 -0
- package/package.json +42 -0
- package/plugin.d.ts +2 -0
- package/plugin.js +7 -0
- package/src/generators/init/init.d.ts +4 -0
- package/src/generators/init/init.js +79 -0
- package/src/generators/init/schema.d.ts +6 -0
- package/src/generators/init/schema.json +34 -0
- package/src/plugin/dependencies.d.ts +2 -0
- package/src/plugin/dependencies.js +80 -0
- package/src/plugin/nodes.d.ts +16 -0
- package/src/plugin/nodes.js +105 -0
- package/src/utils/exec-gradle.d.ts +7 -0
- package/src/utils/exec-gradle.js +45 -0
- package/src/utils/get-gradle-report.d.ts +10 -0
- package/src/utils/get-gradle-report.js +128 -0
- package/src/utils/has-gradle-plugin.d.ts +2 -0
- package/src/utils/has-gradle-plugin.js +9 -0
- package/src/utils/versions.d.ts +1 -0
- package/src/utils/versions.js +4 -0
package/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2017-2023 Narwhal Technologies Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
<p style="text-align: center;">
|
2
|
+
<picture>
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
|
4
|
+
<img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
|
5
|
+
</picture>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<div style="text-align: center;">
|
9
|
+
|
10
|
+
[](https://circleci.com/gh/nrwl/nx)
|
11
|
+
[]()
|
12
|
+
[](https://www.npmjs.com/@nx/workspace)
|
13
|
+
[]()
|
14
|
+
[](http://commitizen.github.io/cz-cli/)
|
15
|
+
[](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
16
|
+
[](https://go.nx.dev/community)
|
17
|
+
|
18
|
+
</div>
|
19
|
+
|
20
|
+
|
21
|
+
<hr>
|
22
|
+
|
23
|
+
# Nx: Smart Monorepos · Fast CI
|
24
|
+
|
25
|
+
Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
|
26
|
+
|
27
|
+
This package is a [Gradle plugin for Nx](https://nx.dev/gradle/overview).
|
28
|
+
|
29
|
+
## Getting Started
|
30
|
+
|
31
|
+
### Creating an Nx Workspace
|
32
|
+
|
33
|
+
**Using `npx`**
|
34
|
+
|
35
|
+
```bash
|
36
|
+
npx create-nx-workspace
|
37
|
+
```
|
38
|
+
|
39
|
+
**Using `npm init`**
|
40
|
+
|
41
|
+
```bash
|
42
|
+
npm init nx-workspace
|
43
|
+
```
|
44
|
+
|
45
|
+
**Using `yarn create`**
|
46
|
+
|
47
|
+
```bash
|
48
|
+
yarn create nx-workspace
|
49
|
+
```
|
50
|
+
|
51
|
+
### Adding Nx to an Existing Repository
|
52
|
+
|
53
|
+
Run:
|
54
|
+
|
55
|
+
```bash
|
56
|
+
npx nx@latest init
|
57
|
+
```
|
58
|
+
|
59
|
+
## Documentation & Resources
|
60
|
+
|
61
|
+
- [Nx.Dev: Documentation, Guides, Tutorials](https://nx.dev)
|
62
|
+
- [Intro to Nx](https://nx.dev/getting-started/intro)
|
63
|
+
- [Official Nx YouTube Channel](https://www.youtube.com/@NxDevtools)
|
64
|
+
- [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
|
65
|
+
|
66
|
+
<p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
|
67
|
+
width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
|
68
|
+
|
package/generators.json
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
{
|
2
|
+
"name": "Nx Gradle",
|
3
|
+
"version": "0.1",
|
4
|
+
"generators": {
|
5
|
+
"init": {
|
6
|
+
"factory": "./src/generators/init/init#initGenerator",
|
7
|
+
"schema": "./src/generators/init/schema.json",
|
8
|
+
"description": "Initializes a Gradle project in the current workspace"
|
9
|
+
}
|
10
|
+
}
|
11
|
+
}
|
package/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './plugin';
|
package/index.js
ADDED
package/migrations.json
ADDED
package/package.json
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
{
|
2
|
+
"name": "@nx/gradle",
|
3
|
+
"version": "18.2.0-beta.0",
|
4
|
+
"private": false,
|
5
|
+
"description": "The Nx Plugin for gradle",
|
6
|
+
"repository": {
|
7
|
+
"type": "git",
|
8
|
+
"url": "https://github.com/nrwl/nx.git",
|
9
|
+
"directory": "packages/gradle"
|
10
|
+
},
|
11
|
+
"keywords": [
|
12
|
+
"Monorepo",
|
13
|
+
"Java",
|
14
|
+
"Gradle",
|
15
|
+
"CLI"
|
16
|
+
],
|
17
|
+
"main": "./index.js",
|
18
|
+
"typings": "./index.d.ts",
|
19
|
+
"author": "Victor Savkin",
|
20
|
+
"license": "MIT",
|
21
|
+
"bugs": {
|
22
|
+
"url": "https://github.com/nrwl/nx/issues"
|
23
|
+
},
|
24
|
+
"homepage": "https://nx.dev",
|
25
|
+
"generators": "./generators.json",
|
26
|
+
"exports": {
|
27
|
+
".": "./index.js",
|
28
|
+
"./package.json": "./package.json",
|
29
|
+
"./migrations.json": "./migrations.json",
|
30
|
+
"./generators.json": "./generators.json"
|
31
|
+
},
|
32
|
+
"nx-migrate": {
|
33
|
+
"migrations": "./migrations.json"
|
34
|
+
},
|
35
|
+
"dependencies": {
|
36
|
+
"@nx/devkit": "18.2.0-beta.0"
|
37
|
+
},
|
38
|
+
"publishConfig": {
|
39
|
+
"access": "public"
|
40
|
+
},
|
41
|
+
"type": "commonjs"
|
42
|
+
}
|
package/plugin.d.ts
ADDED
package/plugin.js
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createNodes = exports.createDependencies = void 0;
|
4
|
+
var dependencies_1 = require("./src/plugin/dependencies");
|
5
|
+
Object.defineProperty(exports, "createDependencies", { enumerable: true, get: function () { return dependencies_1.createDependencies; } });
|
6
|
+
var nodes_1 = require("./src/plugin/nodes");
|
7
|
+
Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return nodes_1.createNodes; } });
|
@@ -0,0 +1,79 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.initGenerator = void 0;
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
5
|
+
const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
|
6
|
+
const nodes_1 = require("../../plugin/nodes");
|
7
|
+
const versions_1 = require("../../utils/versions");
|
8
|
+
const has_gradle_plugin_1 = require("../../utils/has-gradle-plugin");
|
9
|
+
async function initGenerator(tree, options) {
|
10
|
+
const tasks = [];
|
11
|
+
if (!options.skipPackageJson && tree.exists('package.json')) {
|
12
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
13
|
+
'@nx/gradle': versions_1.nxVersion,
|
14
|
+
}, undefined, options.keepExistingVersions));
|
15
|
+
}
|
16
|
+
addPlugin(tree);
|
17
|
+
addProjectReportToBuildGradle(tree);
|
18
|
+
if (options.updatePackageScripts && tree.exists('package.json')) {
|
19
|
+
await (0, update_package_scripts_1.updatePackageScripts)(tree, nodes_1.createNodes);
|
20
|
+
}
|
21
|
+
if (!options.skipFormat) {
|
22
|
+
await (0, devkit_1.formatFiles)(tree);
|
23
|
+
}
|
24
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
25
|
+
}
|
26
|
+
exports.initGenerator = initGenerator;
|
27
|
+
function addPlugin(tree) {
|
28
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
29
|
+
if (!(0, has_gradle_plugin_1.hasGradlePlugin)(tree)) {
|
30
|
+
nxJson.plugins ??= [];
|
31
|
+
nxJson.plugins.push({
|
32
|
+
plugin: '@nx/gradle',
|
33
|
+
options: {
|
34
|
+
testTargetName: 'test',
|
35
|
+
classesTargetName: 'classes',
|
36
|
+
buildTargetName: 'build',
|
37
|
+
},
|
38
|
+
});
|
39
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
/**
|
43
|
+
* This function adds the project-report plugin to the build.gradle or build.gradle.kts file
|
44
|
+
*/
|
45
|
+
function addProjectReportToBuildGradle(tree) {
|
46
|
+
let buildGradleFile;
|
47
|
+
if (tree.exists('settings.gradle.kts')) {
|
48
|
+
buildGradleFile = 'build.gradle.kts';
|
49
|
+
}
|
50
|
+
else if (tree.exists('settings.gradle')) {
|
51
|
+
buildGradleFile = 'build.gradle';
|
52
|
+
}
|
53
|
+
else {
|
54
|
+
throw new Error('Could not find settings.gradle or settings.gradle.kts file in your gradle workspace.');
|
55
|
+
}
|
56
|
+
let buildGradleContent = '';
|
57
|
+
if (tree.exists(buildGradleFile)) {
|
58
|
+
buildGradleContent = tree.read(buildGradleFile).toString();
|
59
|
+
}
|
60
|
+
if (buildGradleContent.includes('allprojects')) {
|
61
|
+
if (!buildGradleContent.includes('"project-report')) {
|
62
|
+
devkit_1.logger.warn(`Please add the project-report plugin to your ${buildGradleFile}:
|
63
|
+
allprojects {
|
64
|
+
apply {
|
65
|
+
plugin("project-report")
|
66
|
+
}
|
67
|
+
}`);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
else {
|
71
|
+
buildGradleContent += `\n\rallprojects {
|
72
|
+
apply {
|
73
|
+
plugin("project-report")
|
74
|
+
}
|
75
|
+
}`;
|
76
|
+
tree.write(buildGradleFile, buildGradleContent);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
exports.default = initGenerator;
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
3
|
+
"$id": "NxGradleInitSchema",
|
4
|
+
"title": "Gradle Init Generator",
|
5
|
+
"description": "Initializes a Gradle project in the current workspace.",
|
6
|
+
"type": "object",
|
7
|
+
"properties": {
|
8
|
+
"skipFormat": {
|
9
|
+
"description": "Skip formatting files.",
|
10
|
+
"type": "boolean",
|
11
|
+
"default": false,
|
12
|
+
"x-priority": "internal"
|
13
|
+
},
|
14
|
+
"skipPackageJson": {
|
15
|
+
"type": "boolean",
|
16
|
+
"default": false,
|
17
|
+
"description": "Do not add dependencies to `package.json`.",
|
18
|
+
"x-priority": "internal"
|
19
|
+
},
|
20
|
+
"keepExistingVersions": {
|
21
|
+
"type": "boolean",
|
22
|
+
"x-priority": "internal",
|
23
|
+
"description": "Keep existing dependencies versions",
|
24
|
+
"default": false
|
25
|
+
},
|
26
|
+
"updatePackageScripts": {
|
27
|
+
"type": "boolean",
|
28
|
+
"x-priority": "internal",
|
29
|
+
"description": "Update `package.json` scripts with inferred targets",
|
30
|
+
"default": false
|
31
|
+
}
|
32
|
+
},
|
33
|
+
"required": []
|
34
|
+
}
|
@@ -0,0 +1,80 @@
|
|
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_fs_1 = require("node:fs");
|
6
|
+
const node_path_1 = require("node:path");
|
7
|
+
const get_gradle_report_1 = require("../utils/get-gradle-report");
|
8
|
+
const nodes_1 = require("./nodes");
|
9
|
+
const createDependencies = async (_, context) => {
|
10
|
+
const gradleFiles = findGradleFiles(context.filesToProcess);
|
11
|
+
if (gradleFiles.length === 0) {
|
12
|
+
return [];
|
13
|
+
}
|
14
|
+
let dependencies = [];
|
15
|
+
const gradleDependenciesStart = performance.mark('gradleDependencies:start');
|
16
|
+
const { gradleFileToGradleProjectMap, gradleProjectToProjectName, buildFileToDepsMap, } = (0, get_gradle_report_1.getGradleReport)();
|
17
|
+
for (const gradleFile of gradleFiles) {
|
18
|
+
const gradleProject = gradleFileToGradleProjectMap.get(gradleFile);
|
19
|
+
const projectName = gradleProjectToProjectName.get(gradleProject);
|
20
|
+
const depsFile = buildFileToDepsMap.get(gradleFile);
|
21
|
+
if (projectName && depsFile) {
|
22
|
+
dependencies = dependencies.concat(Array.from(processGradleDependencies(depsFile, gradleProjectToProjectName, projectName, gradleFile, context)));
|
23
|
+
}
|
24
|
+
}
|
25
|
+
const gradleDependenciesEnd = performance.mark('gradleDependencies:end');
|
26
|
+
performance.measure('gradleDependencies', gradleDependenciesStart.name, gradleDependenciesEnd.name);
|
27
|
+
(0, nodes_1.writeTargetsToCache)(nodes_1.calculatedTargets);
|
28
|
+
if (dependencies.length) {
|
29
|
+
(0, get_gradle_report_1.invalidateGradleReportCache)();
|
30
|
+
}
|
31
|
+
return dependencies;
|
32
|
+
};
|
33
|
+
exports.createDependencies = createDependencies;
|
34
|
+
const gradleConfigFileNames = new Set(['build.gradle', 'build.gradle.kts']);
|
35
|
+
function findGradleFiles(fileMap) {
|
36
|
+
const gradleFiles = [];
|
37
|
+
for (const [_, files] of Object.entries(fileMap.projectFileMap)) {
|
38
|
+
for (const file of files) {
|
39
|
+
if (gradleConfigFileNames.has((0, node_path_1.basename)(file.file))) {
|
40
|
+
gradleFiles.push(file.file);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
return gradleFiles;
|
45
|
+
}
|
46
|
+
function processGradleDependencies(depsFile, gradleProjectToProjectName, sourceProjectName, gradleFile, context) {
|
47
|
+
const dependencies = new Set();
|
48
|
+
const lines = (0, node_fs_1.readFileSync)(depsFile).toString().split('\n');
|
49
|
+
let inDeps = false;
|
50
|
+
for (const line of lines) {
|
51
|
+
if (line.startsWith('implementationDependenciesMetadata') ||
|
52
|
+
line.startsWith('compileClasspath')) {
|
53
|
+
inDeps = true;
|
54
|
+
continue;
|
55
|
+
}
|
56
|
+
if (inDeps) {
|
57
|
+
if (line === '') {
|
58
|
+
inDeps = false;
|
59
|
+
continue;
|
60
|
+
}
|
61
|
+
const [indents, dep] = line.split('--- ');
|
62
|
+
if ((indents === '\\' || indents === '+') && dep.startsWith('project ')) {
|
63
|
+
const gradleProjectName = dep
|
64
|
+
.substring('project '.length)
|
65
|
+
.replace(/ \(n\)$/, '')
|
66
|
+
.trim();
|
67
|
+
const target = gradleProjectToProjectName.get(gradleProjectName);
|
68
|
+
const dependency = {
|
69
|
+
source: sourceProjectName,
|
70
|
+
target,
|
71
|
+
type: devkit_1.DependencyType.static,
|
72
|
+
sourceFile: gradleFile,
|
73
|
+
};
|
74
|
+
(0, devkit_1.validateDependency)(dependency, context);
|
75
|
+
dependencies.add(dependency);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
return dependencies;
|
80
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { CreateNodes, TargetConfiguration } from '@nx/devkit';
|
2
|
+
export interface GradlePluginOptions {
|
3
|
+
testTargetName?: string;
|
4
|
+
classesTargetName?: string;
|
5
|
+
buildTargetName?: string;
|
6
|
+
[taskTargetName: string]: string | undefined;
|
7
|
+
}
|
8
|
+
export declare const calculatedTargets: Record<string, {
|
9
|
+
name: string;
|
10
|
+
targets: Record<string, TargetConfiguration>;
|
11
|
+
}>;
|
12
|
+
export declare function writeTargetsToCache(targets: Record<string, {
|
13
|
+
name: string;
|
14
|
+
targets: Record<string, TargetConfiguration>;
|
15
|
+
}>): void;
|
16
|
+
export declare const createNodes: CreateNodes<GradlePluginOptions>;
|
@@ -0,0 +1,105 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createNodes = exports.writeTargetsToCache = exports.calculatedTargets = void 0;
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
5
|
+
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
6
|
+
const node_fs_1 = require("node:fs");
|
7
|
+
const node_path_1 = require("node:path");
|
8
|
+
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
9
|
+
const exec_gradle_1 = require("../utils/exec-gradle");
|
10
|
+
const get_gradle_report_1 = require("../utils/get-gradle-report");
|
11
|
+
const nonCacheableGradleTaskTypes = new Set(['Application']);
|
12
|
+
const dependsOnMap = {
|
13
|
+
build: ['^build', 'classes'],
|
14
|
+
test: ['classes'],
|
15
|
+
classes: ['^classes'],
|
16
|
+
};
|
17
|
+
const cachePath = (0, node_path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'gradle.hash');
|
18
|
+
const targetsCache = (0, node_fs_1.existsSync)(cachePath) ? readTargetsCache() : {};
|
19
|
+
exports.calculatedTargets = {};
|
20
|
+
function readTargetsCache() {
|
21
|
+
return (0, devkit_1.readJsonFile)(cachePath);
|
22
|
+
}
|
23
|
+
function writeTargetsToCache(targets) {
|
24
|
+
(0, devkit_1.writeJsonFile)(cachePath, targets);
|
25
|
+
}
|
26
|
+
exports.writeTargetsToCache = writeTargetsToCache;
|
27
|
+
exports.createNodes = [
|
28
|
+
'**/build.{gradle.kts,gradle}',
|
29
|
+
(gradleFilePath, options, context) => {
|
30
|
+
const projectRoot = (0, node_path_1.dirname)(gradleFilePath);
|
31
|
+
const hash = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options ?? {}, context);
|
32
|
+
if (targetsCache[hash]) {
|
33
|
+
exports.calculatedTargets[hash] = targetsCache[hash];
|
34
|
+
return {
|
35
|
+
projects: {
|
36
|
+
[projectRoot]: targetsCache[hash],
|
37
|
+
},
|
38
|
+
};
|
39
|
+
}
|
40
|
+
try {
|
41
|
+
const { gradleProjectToTasksTypeMap, gradleFileToOutputDirsMap, gradleFileToGradleProjectMap, gradleProjectToProjectName, } = (0, get_gradle_report_1.getGradleReport)();
|
42
|
+
const gradleProject = gradleFileToGradleProjectMap.get(gradleFilePath);
|
43
|
+
const projectName = gradleProjectToProjectName.get(gradleProject);
|
44
|
+
if (!projectName) {
|
45
|
+
return;
|
46
|
+
}
|
47
|
+
const tasksTypeMap = gradleProjectToTasksTypeMap.get(gradleProject);
|
48
|
+
let tasks = [];
|
49
|
+
for (let [taskName, taskType] of tasksTypeMap.entries()) {
|
50
|
+
tasks.push({
|
51
|
+
type: taskType,
|
52
|
+
name: taskName,
|
53
|
+
});
|
54
|
+
}
|
55
|
+
const outputDirs = gradleFileToOutputDirsMap.get(gradleFilePath);
|
56
|
+
const targets = createGradleTargets(tasks, projectRoot, options, context, outputDirs);
|
57
|
+
exports.calculatedTargets[hash] = {
|
58
|
+
name: projectName,
|
59
|
+
targets,
|
60
|
+
};
|
61
|
+
return {
|
62
|
+
projects: {
|
63
|
+
[projectRoot]: {
|
64
|
+
root: projectRoot,
|
65
|
+
name: projectName,
|
66
|
+
targets,
|
67
|
+
},
|
68
|
+
},
|
69
|
+
};
|
70
|
+
}
|
71
|
+
catch (e) {
|
72
|
+
console.error(e);
|
73
|
+
return {};
|
74
|
+
}
|
75
|
+
},
|
76
|
+
];
|
77
|
+
function createGradleTargets(tasks, projectRoot, options, context, outputDirs) {
|
78
|
+
const inputsMap = createInputsMap(context);
|
79
|
+
const targets = {};
|
80
|
+
for (const task of tasks) {
|
81
|
+
const targetName = options?.[`${task.name}TargetName`] ?? task.name;
|
82
|
+
const outputs = outputDirs.get(task.name);
|
83
|
+
targets[targetName] = {
|
84
|
+
command: `${(0, exec_gradle_1.getGradleBinaryPath)()} ${task.name}`,
|
85
|
+
options: {
|
86
|
+
cwd: projectRoot,
|
87
|
+
},
|
88
|
+
cache: !nonCacheableGradleTaskTypes.has(task.type),
|
89
|
+
inputs: inputsMap[task.name],
|
90
|
+
outputs: outputs ? [outputs] : undefined,
|
91
|
+
dependsOn: dependsOnMap[task.name],
|
92
|
+
};
|
93
|
+
}
|
94
|
+
return targets;
|
95
|
+
}
|
96
|
+
function createInputsMap(context) {
|
97
|
+
const namedInputs = context.nxJsonConfiguration.namedInputs;
|
98
|
+
return {
|
99
|
+
build: namedInputs?.production
|
100
|
+
? ['production', '^production']
|
101
|
+
: ['default', '^default'],
|
102
|
+
test: ['default', namedInputs?.production ? '^production' : '^default'],
|
103
|
+
classes: ['default', '^default'],
|
104
|
+
};
|
105
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
import { ExecFileOptions } from 'child_process';
|
4
|
+
import { ExecFileSyncOptionsWithBufferEncoding } from 'node:child_process';
|
5
|
+
export declare function execGradle(args: string[], execOptions: ExecFileSyncOptionsWithBufferEncoding): Buffer;
|
6
|
+
export declare function getGradleBinaryPath(): string;
|
7
|
+
export declare function execGradleAsync(args: ReadonlyArray<string>, execOptions: ExecFileOptions): Promise<Buffer>;
|
@@ -0,0 +1,45 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.execGradleAsync = exports.getGradleBinaryPath = exports.execGradle = void 0;
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
5
|
+
const node_child_process_1 = require("node:child_process");
|
6
|
+
const node_fs_1 = require("node:fs");
|
7
|
+
const node_path_1 = require("node:path");
|
8
|
+
function execGradle(args, execOptions) {
|
9
|
+
const gradleBinaryPath = getGradleBinaryPath();
|
10
|
+
return (0, node_child_process_1.execFileSync)(gradleBinaryPath, args, execOptions);
|
11
|
+
}
|
12
|
+
exports.execGradle = execGradle;
|
13
|
+
function getGradleBinaryPath() {
|
14
|
+
const gradleFile = process.platform.startsWith('win')
|
15
|
+
? 'gradlew.bat'
|
16
|
+
: 'gradlew';
|
17
|
+
const gradleBinaryPath = (0, node_path_1.join)(devkit_1.workspaceRoot, gradleFile);
|
18
|
+
if (!(0, node_fs_1.existsSync)(gradleBinaryPath)) {
|
19
|
+
throw new Error('Gradle is not setup. Run "gradle init"');
|
20
|
+
}
|
21
|
+
return gradleBinaryPath;
|
22
|
+
}
|
23
|
+
exports.getGradleBinaryPath = getGradleBinaryPath;
|
24
|
+
function execGradleAsync(args, execOptions) {
|
25
|
+
const gradleBinaryPath = getGradleBinaryPath();
|
26
|
+
if (!(0, node_fs_1.existsSync)(gradleBinaryPath)) {
|
27
|
+
throw new Error('Gradle is not setup. Run "gradle init"');
|
28
|
+
}
|
29
|
+
return new Promise((res, rej) => {
|
30
|
+
const cp = (0, node_child_process_1.execFile)(gradleBinaryPath, args, execOptions);
|
31
|
+
let stdout = Buffer.from('');
|
32
|
+
cp.stdout?.on('data', (data) => {
|
33
|
+
stdout += data;
|
34
|
+
});
|
35
|
+
cp.on('exit', (code) => {
|
36
|
+
if (code === 0) {
|
37
|
+
res(stdout);
|
38
|
+
}
|
39
|
+
else {
|
40
|
+
rej(new Error(`Executing Gradle with ${args.join(' ')} failed with code: ${code}. \nLogs: ${stdout}`));
|
41
|
+
}
|
42
|
+
});
|
43
|
+
});
|
44
|
+
}
|
45
|
+
exports.execGradleAsync = execGradleAsync;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
interface GradleReport {
|
2
|
+
gradleFileToGradleProjectMap: Map<string, string>;
|
3
|
+
buildFileToDepsMap: Map<string, string>;
|
4
|
+
gradleFileToOutputDirsMap: Map<string, Map<string, string>>;
|
5
|
+
gradleProjectToTasksTypeMap: Map<string, Map<string, string>>;
|
6
|
+
gradleProjectToProjectName: Map<string, string>;
|
7
|
+
}
|
8
|
+
export declare function invalidateGradleReportCache(): void;
|
9
|
+
export declare function getGradleReport(): GradleReport;
|
10
|
+
export {};
|
@@ -0,0 +1,128 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getGradleReport = exports.invalidateGradleReportCache = void 0;
|
4
|
+
const node_fs_1 = require("node:fs");
|
5
|
+
const node_path_1 = require("node:path");
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
7
|
+
const exec_gradle_1 = require("./exec-gradle");
|
8
|
+
let gradleReportCache;
|
9
|
+
function invalidateGradleReportCache() {
|
10
|
+
gradleReportCache = undefined;
|
11
|
+
}
|
12
|
+
exports.invalidateGradleReportCache = invalidateGradleReportCache;
|
13
|
+
function getGradleReport() {
|
14
|
+
if (gradleReportCache) {
|
15
|
+
return gradleReportCache;
|
16
|
+
}
|
17
|
+
const gradleProjectReportStart = performance.mark('gradleProjectReport:start');
|
18
|
+
const projectReportLines = (0, exec_gradle_1.execGradle)(['projectReport'], {
|
19
|
+
cwd: devkit_1.workspaceRoot,
|
20
|
+
})
|
21
|
+
.toString()
|
22
|
+
.split('\n');
|
23
|
+
const gradleProjectReportEnd = performance.mark('gradleProjectReport:end');
|
24
|
+
performance.measure('gradleProjectReport', gradleProjectReportStart.name, gradleProjectReportEnd.name);
|
25
|
+
gradleReportCache = processProjectReports(projectReportLines);
|
26
|
+
return gradleReportCache;
|
27
|
+
}
|
28
|
+
exports.getGradleReport = getGradleReport;
|
29
|
+
function processProjectReports(projectReportLines) {
|
30
|
+
/**
|
31
|
+
* Map of Gradle File path to Gradle Project Name
|
32
|
+
*/
|
33
|
+
const gradleFileToGradleProjectMap = new Map();
|
34
|
+
/**
|
35
|
+
* Map of Gradle Project Name to Gradle File
|
36
|
+
*/
|
37
|
+
const gradleProjectToGradleFileMap = new Map();
|
38
|
+
const dependenciesMap = new Map();
|
39
|
+
/**
|
40
|
+
* Map of Gradle Build File to tasks type map
|
41
|
+
*/
|
42
|
+
const gradleProjectToTasksTypeMap = new Map();
|
43
|
+
const gradleProjectToProjectName = new Map();
|
44
|
+
/**
|
45
|
+
* Map of buildFile to dependencies report path
|
46
|
+
*/
|
47
|
+
const buildFileToDepsMap = new Map();
|
48
|
+
/**
|
49
|
+
* Map fo possible output files of each gradle file
|
50
|
+
* e.g. {build.gradle.kts: { projectReportDir: '' testReportDir: '' }}
|
51
|
+
*/
|
52
|
+
const gradleFileToOutputDirsMap = new Map();
|
53
|
+
projectReportLines.forEach((line, index) => {
|
54
|
+
if (line.startsWith('> Task ')) {
|
55
|
+
const nextLine = projectReportLines[index + 1];
|
56
|
+
if (line.endsWith(':dependencyReport')) {
|
57
|
+
const gradleProject = line.substring('> Task '.length, line.length - ':dependencyReport'.length);
|
58
|
+
const [_, file] = nextLine.split('file://');
|
59
|
+
dependenciesMap.set(gradleProject, file);
|
60
|
+
}
|
61
|
+
if (line.endsWith('propertyReport')) {
|
62
|
+
const gradleProject = line.substring('> Task '.length, line.length - ':propertyReport'.length);
|
63
|
+
const [_, file] = nextLine.split('file://');
|
64
|
+
const propertyReportLines = (0, node_fs_1.readFileSync)(file).toString().split('\n');
|
65
|
+
let projectName, absBuildFilePath, absBuildDirPath;
|
66
|
+
const outputDirMap = new Map();
|
67
|
+
for (const line of propertyReportLines) {
|
68
|
+
if (line.startsWith('name: ')) {
|
69
|
+
projectName = line.substring('name: '.length);
|
70
|
+
}
|
71
|
+
if (line.startsWith('buildFile: ')) {
|
72
|
+
absBuildFilePath = line.substring('buildFile: '.length);
|
73
|
+
}
|
74
|
+
if (line.startsWith('buildDir: ')) {
|
75
|
+
absBuildDirPath = line.substring('buildDir: '.length);
|
76
|
+
}
|
77
|
+
if (line.includes('Dir: ')) {
|
78
|
+
const [dirName, dirPath] = line.split(': ');
|
79
|
+
const taskName = dirName.replace('Dir', '');
|
80
|
+
outputDirMap.set(taskName, `{workspaceRoot}/${(0, node_path_1.relative)(devkit_1.workspaceRoot, dirPath)}`);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
if (!projectName || !absBuildFilePath || !absBuildDirPath) {
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
const buildFile = (0, node_path_1.relative)(devkit_1.workspaceRoot, absBuildFilePath);
|
87
|
+
const buildDir = (0, node_path_1.relative)(devkit_1.workspaceRoot, absBuildDirPath);
|
88
|
+
buildFileToDepsMap.set(buildFile, dependenciesMap.get(gradleProject));
|
89
|
+
outputDirMap.set('build', `{workspaceRoot}/${buildDir}`);
|
90
|
+
outputDirMap.set('classes', `{workspaceRoot}/${(0, node_path_1.join)(buildDir, 'classes')}`);
|
91
|
+
gradleFileToOutputDirsMap.set(buildFile, outputDirMap);
|
92
|
+
gradleFileToGradleProjectMap.set(buildFile, gradleProject);
|
93
|
+
gradleProjectToGradleFileMap.set(gradleProject, buildFile);
|
94
|
+
gradleProjectToProjectName.set(gradleProject, projectName);
|
95
|
+
}
|
96
|
+
if (line.endsWith('taskReport')) {
|
97
|
+
const gradleProject = line.substring('> Task '.length, line.length - ':taskReport'.length);
|
98
|
+
const [_, file] = nextLine.split('file://');
|
99
|
+
const taskTypeMap = new Map();
|
100
|
+
const tasksFileLines = (0, node_fs_1.readFileSync)(file).toString().split('\n');
|
101
|
+
let i = 0;
|
102
|
+
while (i < tasksFileLines.length) {
|
103
|
+
const line = tasksFileLines[i];
|
104
|
+
if (line.endsWith('tasks')) {
|
105
|
+
const dashes = new Array(line.length + 1).join('-');
|
106
|
+
if (tasksFileLines[i + 1] === dashes) {
|
107
|
+
const type = line.substring(0, line.length - ' tasks'.length);
|
108
|
+
i++;
|
109
|
+
while (tasksFileLines[++i] !== '') {
|
110
|
+
const [taskName] = tasksFileLines[i].split(' - ');
|
111
|
+
taskTypeMap.set(taskName, type);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
i++;
|
116
|
+
}
|
117
|
+
gradleProjectToTasksTypeMap.set(gradleProject, taskTypeMap);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
});
|
121
|
+
return {
|
122
|
+
gradleFileToGradleProjectMap,
|
123
|
+
buildFileToDepsMap,
|
124
|
+
gradleFileToOutputDirsMap,
|
125
|
+
gradleProjectToTasksTypeMap,
|
126
|
+
gradleProjectToProjectName,
|
127
|
+
};
|
128
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.hasGradlePlugin = void 0;
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
5
|
+
function hasGradlePlugin(tree) {
|
6
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
7
|
+
return !!nxJson.plugins?.some((p) => typeof p === 'string' ? p === '@nx/gradle' : p.plugin === '@nx/gradle');
|
8
|
+
}
|
9
|
+
exports.hasGradlePlugin = hasGradlePlugin;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const nxVersion: any;
|