@nx/gradle 21.2.3 → 21.3.0-beta.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/gradle",
3
- "version": "21.2.3",
3
+ "version": "21.3.0-beta.1",
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.3"
38
+ "@nx/devkit": "21.3.0-beta.1"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"
@@ -17,13 +17,11 @@ async function gradleExecutor(options, context) {
17
17
  if (options.testClassName) {
18
18
  args.push(`--tests`, options.testClassName);
19
19
  }
20
- if (options.excludeDependsOn) {
21
- (0, get_exclude_task_1.getExcludeTasks)(new Set([`${context.projectName}:${context.targetName}`]), context.projectGraph.nodes).forEach((task) => {
22
- if (task) {
23
- args.push('--exclude-task', task);
24
- }
25
- });
26
- }
20
+ (0, get_exclude_task_1.getExcludeTasks)(new Set([`${context.projectName}:${context.targetName}`]), context.projectGraph.nodes).forEach((task) => {
21
+ if (task) {
22
+ args.push('--exclude-task', task);
23
+ }
24
+ });
27
25
  try {
28
26
  const { success } = await (0, run_commands_impl_1.default)({
29
27
  command: `${gradlewPath} ${options.taskName}`,
@@ -21,15 +21,13 @@ jobs:
21
21
  # Run this command as early as possible, before dependencies are installed
22
22
  # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun
23
23
  <% 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<% } %>
24
- # - run: ./nx start-ci-run --distribute-on="3 linux-medium-jvm" --stop-agents-after="check"
24
+ # - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="3 linux-medium-jvm" --stop-agents-after="check"
25
25
 
26
26
  - nx/set-shas:
27
27
  main-branch-name: '<%= mainBranch %>'
28
- <% for (const command of commands) { %><% if (command.comments) { %><% for (const comment of command.comments) { %>
29
- # <%- comment %><% } %><% } %><% if (command.command) { %>
30
- - run:
31
- command: <%= command.command %><% if (command.alwaysRun) { %>
32
- when: always<% } %><% } %><% } %>
28
+ <% for (const command of commands) { %>
29
+ <% if (command.command) { %>- run: <%= command.command %><% } else if (command.comments) { %><% for (const comment of command.comments) { %>
30
+ <%= comment %><% } %><% } else {%>- run: <%= command %><% } %><% } %>
33
31
 
34
32
  workflows:
35
33
  version: 2
@@ -26,7 +26,7 @@ jobs:
26
26
  # Run this command as early as possible, before dependencies are installed
27
27
  # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun
28
28
  <% 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<% } %>
29
- # - run: ./nx start-ci-run --distribute-on="3 linux-medium-jvm" --stop-agents-after="check"
29
+ # - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="3 linux-medium-jvm" --stop-agents-after="check"
30
30
 
31
31
  - name: Set up JDK 21 for x64
32
32
  uses: actions/setup-java@v4
@@ -39,7 +39,6 @@ jobs:
39
39
  uses: gradle/actions/setup-gradle@v3
40
40
 
41
41
  - uses: nrwl/nx-set-shas@v4
42
- <% for (const command of commands) { %><% if (command.comments) { %><% for (const comment of command.comments) { %>
43
- # <%- comment %><% } %><% } %><% if (command.command) { %>
44
- - run: <%= command.command %><% if (command.alwaysRun) { %>
45
- if: always()<% } %><% } %><% } %>
42
+ <% for (const command of commands) { %>
43
+ <% if (command.command) { %>- run: <%= command.command %><% } else if (command.comments) { %><% for (const comment of command.comments) { %>
44
+ <%= comment %><% } %><% } else {%>- run: <%= command %><% } %><% } %>
@@ -1,9 +1,9 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  export type Command = {
3
- command?: string;
4
- comments?: string[];
5
- alwaysRun?: boolean;
6
- };
3
+ command: string;
4
+ } | {
5
+ comments: string[];
6
+ } | string;
7
7
  export interface Schema {
8
8
  name: string;
9
9
  ci: 'github' | 'circleci';
@@ -11,12 +11,13 @@ function getCiCommands(ci) {
11
11
  return [
12
12
  {
13
13
  comments: [
14
- `Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected.`,
15
- `Change from check to check-ci if you turn on the atomizer. Learn more: https://nx.dev/nx-api/gradle#splitting-e2e-tests.`,
14
+ `# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected.`,
15
+ `# Change from check to check-ci if you turn on the atomizer. Learn more: https://nx.dev/nx-api/gradle#splitting-e2e-tests.`,
16
16
  ],
17
+ },
18
+ {
17
19
  command: `./nx affected --base=$NX_BASE --head=$NX_HEAD -t assemble check`,
18
20
  },
19
- getNxCloudFixCiCommand(),
20
21
  ];
21
22
  }
22
23
  default: {
@@ -26,22 +27,12 @@ function getCiCommands(ci) {
26
27
  `# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected.`,
27
28
  `# Change from check to check-ci if you turn on the atomizer. Learn more: https://nx.dev/nx-api/gradle#splitting-tests`,
28
29
  ],
29
- command: `./nx affected -t assemble check`,
30
30
  },
31
- getNxCloudFixCiCommand(),
31
+ { command: `./nx affected -t assemble check` },
32
32
  ];
33
33
  }
34
34
  }
35
35
  }
36
- function getNxCloudFixCiCommand() {
37
- return {
38
- comments: [
39
- `Nx Cloud recommends fixes for failures to help you get CI green faster. Learn more: https://nx.dev/ci/features/self-healing-ci`,
40
- ],
41
- command: `./nx fix-ci`,
42
- alwaysRun: true,
43
- };
44
- }
45
36
  async function ciWorkflowGenerator(tree, schema) {
46
37
  const ci = schema.ci;
47
38
  const options = getTemplateData(tree, schema);
@@ -50,6 +41,8 @@ async function ciWorkflowGenerator(tree, schema) {
50
41
  }
51
42
  function getTemplateData(tree, options) {
52
43
  const { name: workflowName, fileName: workflowFileName } = (0, devkit_1.names)(options.name);
44
+ const packageManager = (0, devkit_1.detectPackageManager)();
45
+ const { exec: packageManagerPrefix } = (0, devkit_1.getPackageManagerCommand)(packageManager);
53
46
  let nxCloudHost = 'nx.app';
54
47
  try {
55
48
  const nxCloudUrl = (0, nx_cloud_utils_1.getNxCloudUrl)((0, devkit_1.readNxJson)(tree));
@@ -62,6 +55,8 @@ function getTemplateData(tree, options) {
62
55
  return {
63
56
  workflowName,
64
57
  workflowFileName,
58
+ packageManager,
59
+ packageManagerPrefix,
65
60
  commands,
66
61
  mainBranch,
67
62
  nxCloudHost,
@@ -20,17 +20,14 @@ function writeTargetsToCache(cachePath, results) {
20
20
  exports.createNodesV2 = [
21
21
  split_config_files_1.gradleConfigAndTestGlob,
22
22
  async (files, options, context) => {
23
- const { buildFiles: buildFilesFromSplitConfigFiles, gradlewFiles } = (0, split_config_files_1.splitConfigFiles)(files);
23
+ const { buildFiles, gradlewFiles } = (0, split_config_files_1.splitConfigFiles)(files);
24
24
  const optionsHash = (0, file_hasher_1.hashObject)(options);
25
25
  const cachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, `gradle-${optionsHash}.hash`);
26
26
  const projectsCache = readProjectsCache(cachePath);
27
27
  await (0, get_project_graph_from_gradle_plugin_1.populateProjectGraph)(context.workspaceRoot, gradlewFiles.map((f) => (0, node_path_1.join)(context.workspaceRoot, f)), options);
28
- const report = (0, get_project_graph_from_gradle_plugin_1.getCurrentProjectGraphReport)();
29
- const { nodes, externalNodes, buildFiles = [] } = report;
30
- // Combine buildFilesFromSplitConfigFiles and buildFiles, making each value distinct
31
- const allBuildFiles = Array.from(new Set([...buildFilesFromSplitConfigFiles, ...buildFiles]));
28
+ const { nodes, externalNodes } = (0, get_project_graph_from_gradle_plugin_1.getCurrentProjectGraphReport)();
32
29
  try {
33
- return (0, devkit_1.createNodesFromFiles)((0, exports.makeCreateNodesForGradleConfigFile)(nodes, projectsCache, externalNodes), allBuildFiles, options, context);
30
+ return (0, devkit_1.createNodesFromFiles)((0, exports.makeCreateNodesForGradleConfigFile)(nodes, projectsCache, externalNodes), buildFiles, options, context);
34
31
  }
35
32
  finally {
36
33
  writeTargetsToCache(cachePath, projectsCache);
@@ -1,5 +1,4 @@
1
1
  {
2
- "buildFiles": ["nested/nested/proj/build.gradle"],
3
2
  "nodes": {
4
3
  "nested/nested/proj": {
5
4
  "targets": {
@@ -1,5 +1,4 @@
1
1
  {
2
- "buildFiles": ["proj/build.gradle"],
3
2
  "nodes": {
4
3
  "proj": {
5
4
  "targets": {
@@ -6,14 +6,12 @@ export interface ProjectGraphReport {
6
6
  };
7
7
  dependencies: Array<StaticDependency>;
8
8
  externalNodes?: Record<string, ProjectGraphExternalNode>;
9
- buildFiles?: string[];
10
9
  }
11
10
  export interface ProjectGraphReportCache extends ProjectGraphReport {
12
11
  hash: string;
13
12
  }
14
13
  export declare function writeProjectGraphReportToCache(cachePath: string, results: ProjectGraphReport): void;
15
14
  export declare function getCurrentProjectGraphReport(): ProjectGraphReport;
16
- export declare function getCurrentBuildFiles(): string[];
17
15
  /**
18
16
  * This function populates the gradle report cache.
19
17
  * For each gradlew file, it runs the `nxProjectGraph` task and processes the output.
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.writeProjectGraphReportToCache = writeProjectGraphReportToCache;
4
4
  exports.getCurrentProjectGraphReport = getCurrentProjectGraphReport;
5
- exports.getCurrentBuildFiles = getCurrentBuildFiles;
6
5
  exports.populateProjectGraph = populateProjectGraph;
7
6
  exports.processNxProjectGraph = processNxProjectGraph;
8
7
  const node_fs_1 = require("node:fs");
@@ -43,10 +42,6 @@ function getCurrentProjectGraphReport() {
43
42
  }
44
43
  return projectGraphReportCache;
45
44
  }
46
- function getCurrentBuildFiles() {
47
- const report = getCurrentProjectGraphReport();
48
- return report.buildFiles || [];
49
- }
50
45
  /**
51
46
  * This function populates the gradle report cache.
52
47
  * For each gradlew file, it runs the `nxProjectGraph` task and processes the output.
@@ -89,7 +84,6 @@ function processNxProjectGraph(projectGraphLines) {
89
84
  dependencies: [],
90
85
  externalNodes: {},
91
86
  };
92
- const allBuildFiles = new Set();
93
87
  while (index < projectGraphLines.length) {
94
88
  const line = projectGraphLines[index].trim();
95
89
  if (line.startsWith('> Task ') && line.endsWith(':nxProjectGraph')) {
@@ -112,13 +106,8 @@ function processNxProjectGraph(projectGraphLines) {
112
106
  ...projectGraphReportJson.externalNodes,
113
107
  };
114
108
  }
115
- if (projectGraphReportJson.buildFiles) {
116
- projectGraphReportJson.buildFiles.forEach((buildFile) => allBuildFiles.add(buildFile));
117
- }
118
109
  }
119
110
  index++;
120
111
  }
121
- // Convert Set to array for the final result
122
- projectGraphReportForAllProjects.buildFiles = Array.from(allBuildFiles);
123
112
  return projectGraphReportForAllProjects;
124
113
  }