@nx/gradle 22.7.0-beta.7 → 22.7.0-beta.9

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/migrations.json CHANGED
@@ -113,6 +113,12 @@
113
113
  "cli": "nx",
114
114
  "description": "Change dev.nx.gradle.project-graph to version 0.1.17 in build file",
115
115
  "factory": "./src/migrations/22-7-0/change-plugin-version-0-1-17"
116
+ },
117
+ "change-plugin-version-0-1-18": {
118
+ "version": "22.7.0-beta.9",
119
+ "cli": "nx",
120
+ "description": "Change dev.nx.gradle.project-graph to version 0.1.18 in build file",
121
+ "factory": "./src/migrations/22-7-0/change-plugin-version-0-1-18"
116
122
  }
117
123
  },
118
124
  "packageJsonUpdates": {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/gradle",
3
- "version": "22.7.0-beta.7",
3
+ "version": "22.7.0-beta.9",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Gradle allows Gradle tasks to be run through Nx",
6
6
  "repository": {
@@ -40,12 +40,12 @@
40
40
  "migrations": "./migrations.json"
41
41
  },
42
42
  "dependencies": {
43
- "@nx/devkit": "22.7.0-beta.7",
43
+ "@nx/devkit": "22.7.0-beta.9",
44
44
  "toml-eslint-parser": "^0.10.0",
45
45
  "tslib": "^2.3.0"
46
46
  },
47
47
  "devDependencies": {
48
- "nx": "22.7.0-beta.7"
48
+ "nx": "22.7.0-beta.9"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"
@@ -1,4 +1,4 @@
1
- import { ProjectGraphProjectNode } from 'nx/src/config/project-graph';
1
+ import { ProjectGraphProjectNode, Target } from '@nx/devkit';
2
2
  /**
3
3
  * Returns Gradle CLI arguments to exclude dependent tasks
4
4
  * that are not part of the current execution set.
@@ -6,13 +6,13 @@ import { ProjectGraphProjectNode } from 'nx/src/config/project-graph';
6
6
  * For example, if a project defines `dependsOn: ['lint']` for the `test` target,
7
7
  * and only `test` is running, this will return: ['lint']
8
8
  *
9
- * @param taskIds - Set of Nx task IDs to process
9
+ * @param tasks - Set of Target to process
10
10
  * @param nodes - Project graph nodes
11
- * @param runningTaskIds - Set of task IDs that are currently running (won't be excluded)
11
+ * @param runningTasks - Set of Target that are currently running (won't be excluded)
12
12
  * @param includeDependsOnTasks - Set of Gradle task names that should be included (not excluded)
13
13
  * (typically provider-based dependencies that Gradle must resolve)
14
14
  */
15
- export declare function getExcludeTasks(taskIds: Set<string>, nodes: Record<string, ProjectGraphProjectNode>, runningTaskIds?: Set<string>, includeDependsOnTasks?: Set<string>): Set<string>;
16
- export declare function getGradleTaskNameWithNxTaskId(nxTaskId: string, nodes: Record<string, ProjectGraphProjectNode>): string | null;
17
- export declare function getAllDependsOn(nodes: Record<string, ProjectGraphProjectNode>, projectName: string, targetName: string): Set<string>;
15
+ export declare function getExcludeTasks(tasks: Set<Target>, nodes: Record<string, ProjectGraphProjectNode>, runningTasks?: Set<Target>, includeDependsOnTasks?: Set<string>): Set<string>;
16
+ export declare function getGradleTaskName(pt: Target, nodes: Record<string, ProjectGraphProjectNode>): string | null;
17
+ export declare function getAllDependsOn(nodes: Record<string, ProjectGraphProjectNode>, projectName: string, targetName: string): Set<Target>;
18
18
  //# sourceMappingURL=get-exclude-task.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-exclude-task.d.ts","sourceRoot":"","sources":["../../../../../../packages/gradle/src/executors/gradle/get-exclude-task.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AAgCrC;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,EACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,EAC9C,cAAc,GAAE,GAAG,CAAC,MAAM,CAAa,EACvC,qBAAqB,GAAE,GAAG,CAAC,MAAM,CAAa,GAC7C,GAAG,CAAC,MAAM,CAAC,CAmBb;AAED,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,GAC7C,MAAM,GAAG,IAAI,CAKf;AAED,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,EAC9C,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,GAAG,CAAC,MAAM,CAAC,CAyBb"}
1
+ {"version":3,"file":"get-exclude-task.d.ts","sourceRoot":"","sources":["../../../../../../packages/gradle/src/executors/gradle/get-exclude-task.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,MAAM,EAEP,MAAM,YAAY,CAAC;AA+BpB;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,EAClB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,EAC9C,YAAY,GAAE,GAAG,CAAC,MAAM,CAAa,EACrC,qBAAqB,GAAE,GAAG,CAAC,MAAM,CAAa,GAC7C,GAAG,CAAC,MAAM,CAAC,CAsBb;AAED,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,GAC7C,MAAM,GAAG,IAAI,CAEf;AAED,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,EAC9C,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,GAAG,CAAC,MAAM,CAAC,CAgCb"}
@@ -1,17 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getExcludeTasks = getExcludeTasks;
4
- exports.getGradleTaskNameWithNxTaskId = getGradleTaskNameWithNxTaskId;
4
+ exports.getGradleTaskName = getGradleTaskName;
5
5
  exports.getAllDependsOn = getAllDependsOn;
6
+ const devkit_1 = require("@nx/devkit");
6
7
  /**
7
- * Resolves a dependsOn entry to an Nx task ID (project:target format).
8
- * Handles both string format ("project:target") and object format
8
+ * Resolves a dependsOn entry to a Target.
9
+ * Handles both string format ("target") and object format
9
10
  * ({ target: "name", projects?: ["proj1"] }).
10
11
  * For same-project object deps (no projects field), uses the owning project name.
11
12
  */
12
- function resolveDepToTaskId(dep, owningProject) {
13
+ function resolveDepToTarget(dep, owningProject) {
13
14
  if (typeof dep === 'string') {
14
- return dep;
15
+ return { project: owningProject, target: dep };
15
16
  }
16
17
  const target = dep?.target;
17
18
  if (!target) {
@@ -21,13 +22,12 @@ function resolveDepToTaskId(dep, owningProject) {
21
22
  const projectList = Array.isArray(dep.projects)
22
23
  ? dep.projects
23
24
  : [dep.projects];
24
- // For cross-project deps, use the first project
25
- return projectList[0] !== 'self'
26
- ? `${projectList[0]}:${target}`
27
- : `${owningProject}:${target}`;
25
+ return {
26
+ project: projectList[0] !== 'self' ? projectList[0] : owningProject,
27
+ target,
28
+ };
28
29
  }
29
- // Same-project dep (no projects field)
30
- return `${owningProject}:${target}`;
30
+ return { project: owningProject, target };
31
31
  }
32
32
  /**
33
33
  * Returns Gradle CLI arguments to exclude dependent tasks
@@ -36,21 +36,21 @@ function resolveDepToTaskId(dep, owningProject) {
36
36
  * For example, if a project defines `dependsOn: ['lint']` for the `test` target,
37
37
  * and only `test` is running, this will return: ['lint']
38
38
  *
39
- * @param taskIds - Set of Nx task IDs to process
39
+ * @param tasks - Set of Target to process
40
40
  * @param nodes - Project graph nodes
41
- * @param runningTaskIds - Set of task IDs that are currently running (won't be excluded)
41
+ * @param runningTasks - Set of Target that are currently running (won't be excluded)
42
42
  * @param includeDependsOnTasks - Set of Gradle task names that should be included (not excluded)
43
43
  * (typically provider-based dependencies that Gradle must resolve)
44
44
  */
45
- function getExcludeTasks(taskIds, nodes, runningTaskIds = new Set(), includeDependsOnTasks = new Set()) {
45
+ function getExcludeTasks(tasks, nodes, runningTasks = new Set(), includeDependsOnTasks = new Set()) {
46
46
  const excludes = new Set();
47
- for (const taskId of taskIds) {
48
- const [project, target] = taskId.split(':');
49
- const taskDeps = nodes[project]?.data?.targets?.[target]?.dependsOn ?? [];
47
+ const runningKeys = new Set(Array.from(runningTasks).map(devkit_1.targetToTargetString));
48
+ for (const task of tasks) {
49
+ const taskDeps = nodes[task.project]?.data?.targets?.[task.target]?.dependsOn ?? [];
50
50
  for (const dep of taskDeps) {
51
- const depTaskId = resolveDepToTaskId(dep, project);
52
- if (depTaskId && !runningTaskIds.has(depTaskId)) {
53
- const gradleTaskName = getGradleTaskNameWithNxTaskId(depTaskId, nodes);
51
+ const depPt = resolveDepToTarget(dep, task.project);
52
+ if (depPt && !runningKeys.has((0, devkit_1.targetToTargetString)(depPt))) {
53
+ const gradleTaskName = getGradleTaskName(depPt, nodes);
54
54
  if (gradleTaskName && !includeDependsOnTasks.has(gradleTaskName)) {
55
55
  excludes.add(gradleTaskName);
56
56
  }
@@ -59,29 +59,34 @@ function getExcludeTasks(taskIds, nodes, runningTaskIds = new Set(), includeDepe
59
59
  }
60
60
  return excludes;
61
61
  }
62
- function getGradleTaskNameWithNxTaskId(nxTaskId, nodes) {
63
- const [projectName, targetName] = nxTaskId.split(':');
64
- const gradleTaskName = nodes[projectName]?.data?.targets?.[targetName]?.options?.taskName;
65
- return gradleTaskName;
62
+ function getGradleTaskName(pt, nodes) {
63
+ return nodes[pt.project]?.data?.targets?.[pt.target]?.options?.taskName;
66
64
  }
67
65
  function getAllDependsOn(nodes, projectName, targetName) {
68
66
  const allDependsOn = new Set();
69
- const stack = [`${projectName}:${targetName}`];
67
+ const result = new Set();
68
+ const startKey = (0, devkit_1.targetToTargetString)({
69
+ project: projectName,
70
+ target: targetName,
71
+ });
72
+ const stack = [{ project: projectName, target: targetName }];
70
73
  while (stack.length > 0) {
71
- const currentTaskId = stack.pop();
72
- if (currentTaskId && !allDependsOn.has(currentTaskId)) {
73
- allDependsOn.add(currentTaskId);
74
- const [currentProjectName, currentTargetName] = currentTaskId.split(':');
75
- const directDependencies = nodes[currentProjectName]?.data?.targets?.[currentTargetName]
76
- ?.dependsOn ?? [];
74
+ const current = stack.pop();
75
+ const key = (0, devkit_1.targetToTargetString)(current);
76
+ if (!allDependsOn.has(key)) {
77
+ allDependsOn.add(key);
78
+ if (key !== startKey) {
79
+ result.add(current);
80
+ }
81
+ const directDependencies = nodes[current.project]?.data?.targets?.[current.target]?.dependsOn ??
82
+ [];
77
83
  for (const dep of directDependencies) {
78
- const depTaskId = resolveDepToTaskId(dep, currentProjectName);
79
- if (depTaskId && !allDependsOn.has(depTaskId)) {
80
- stack.push(depTaskId);
84
+ const depPt = resolveDepToTarget(dep, current.project);
85
+ if (depPt && !allDependsOn.has((0, devkit_1.targetToTargetString)(depPt))) {
86
+ stack.push(depPt);
81
87
  }
82
88
  }
83
89
  }
84
90
  }
85
- allDependsOn.delete(`${projectName}:${targetName}`); // Exclude the starting task itself
86
- return allDependsOn;
91
+ return result;
87
92
  }
@@ -1 +1 @@
1
- {"version":3,"file":"gradle-batch.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/gradle/src/executors/gradle/gradle-batch.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAEf,uBAAuB,EACvB,SAAS,EAEV,MAAM,YAAY,CAAC;AACpB,OAAO,EAEL,kBAAkB,EACnB,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAchD,eAAO,MAAM,eAAe,QAG3B,CAAC;AAEF,wBAA8B,WAAW,CACvC,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,EAC5C,SAAS,EAAE,kBAAkB,EAC7B,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,YAAY,CAAC,CAkEvB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,EAC5C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC;;;;EAiE/C"}
1
+ {"version":3,"file":"gradle-batch.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/gradle/src/executors/gradle/gradle-batch.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAEf,uBAAuB,EAEvB,SAAS,EAEV,MAAM,YAAY,CAAC;AACpB,OAAO,EAEL,kBAAkB,EACnB,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAchD,eAAO,MAAM,eAAe,QAG3B,CAAC;AAEF,wBAA8B,WAAW,CACvC,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,EAC5C,SAAS,EAAE,kBAAkB,EAC7B,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,YAAY,CAAC,CAkEvB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,EAC5C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC;;;;EAuE/C"}
@@ -56,49 +56,53 @@ async function gradleBatch(taskGraph, inputs, overrides, context) {
56
56
  * Get the gradlew task ids to run
57
57
  */
58
58
  function getGradlewTasksToRun(taskIds, taskGraph, inputs, nodes) {
59
- const taskIdsWithExclude = new Set([]);
60
- const testTaskIdsWithExclude = new Set([]);
61
- const taskIdsWithoutExclude = new Set([]);
59
+ const tasksWithExclude = new Set();
60
+ const testTasksWithExclude = new Set();
61
+ const tasksWithoutExclude = new Set();
62
62
  const gradlewTasksToRun = {};
63
63
  const includeDependsOnTasks = new Set();
64
64
  for (const taskId of taskIds) {
65
65
  const task = taskGraph.tasks[taskId];
66
66
  const input = inputs[task.id];
67
+ const taskTarget = {
68
+ project: task.target.project,
69
+ target: task.target.target,
70
+ };
67
71
  gradlewTasksToRun[taskId] = input;
68
- // Collect tasks that should be included (not excluded) - typically provider-based dependencies
69
72
  if (input.includeDependsOnTasks) {
70
- for (const task of input.includeDependsOnTasks) {
71
- includeDependsOnTasks.add(task);
73
+ for (const t of input.includeDependsOnTasks) {
74
+ includeDependsOnTasks.add(t);
72
75
  }
73
76
  }
74
77
  if (input.excludeDependsOn) {
75
78
  if (input.testClassName) {
76
- testTaskIdsWithExclude.add(taskId);
79
+ testTasksWithExclude.add(taskTarget);
77
80
  }
78
81
  else {
79
- taskIdsWithExclude.add(taskId);
82
+ tasksWithExclude.add(taskTarget);
80
83
  }
81
84
  }
82
85
  else {
83
- taskIdsWithoutExclude.add(taskId);
86
+ tasksWithoutExclude.add(taskTarget);
84
87
  }
85
88
  }
86
- const allDependsOn = new Set(taskIds);
87
- for (const taskId of taskIdsWithoutExclude) {
88
- const [projectName, targetName] = taskId.split(':');
89
- const dependencies = (0, get_exclude_task_1.getAllDependsOn)(nodes, projectName, targetName);
90
- dependencies.forEach((dep) => allDependsOn.add(dep));
89
+ const allRunning = new Set(taskIds.map((id) => ({
90
+ project: taskGraph.tasks[id].target.project,
91
+ target: taskGraph.tasks[id].target.target,
92
+ })));
93
+ for (const task of tasksWithoutExclude) {
94
+ const dependencies = (0, get_exclude_task_1.getAllDependsOn)(nodes, task.project, task.target);
95
+ dependencies.forEach((dep) => allRunning.add(dep));
91
96
  }
92
- const excludeTasks = (0, get_exclude_task_1.getExcludeTasks)(taskIdsWithExclude, nodes, allDependsOn, includeDependsOnTasks);
97
+ const excludeTasks = (0, get_exclude_task_1.getExcludeTasks)(tasksWithExclude, nodes, allRunning, includeDependsOnTasks);
93
98
  const allTestsDependsOn = new Set();
94
- for (const taskId of testTaskIdsWithExclude) {
95
- const [projectName, targetName] = taskId.split(':');
96
- const taskDependsOn = (0, get_exclude_task_1.getAllDependsOn)(nodes, projectName, targetName);
99
+ for (const task of testTasksWithExclude) {
100
+ const taskDependsOn = (0, get_exclude_task_1.getAllDependsOn)(nodes, task.project, task.target);
97
101
  taskDependsOn.forEach((dep) => allTestsDependsOn.add(dep));
98
102
  }
99
103
  const excludeTestTasks = new Set();
100
- for (let taskId of allTestsDependsOn) {
101
- const gradleTaskName = (0, get_exclude_task_1.getGradleTaskNameWithNxTaskId)(taskId, nodes);
104
+ for (const task of allTestsDependsOn) {
105
+ const gradleTaskName = (0, get_exclude_task_1.getGradleTaskName)(task, nodes);
102
106
  if (gradleTaskName) {
103
107
  excludeTestTasks.add(gradleTaskName);
104
108
  }
@@ -46,7 +46,7 @@ async function gradleExecutor(options, context) {
46
46
  });
47
47
  if (options.excludeDependsOn) {
48
48
  const includeDependsOnTasks = new Set(options.includeDependsOnTasks ?? []);
49
- (0, get_exclude_task_1.getExcludeTasks)(new Set([`${context.projectName}:${context.targetName}`]), context.projectGraph.nodes, new Set(), includeDependsOnTasks).forEach((task) => {
49
+ (0, get_exclude_task_1.getExcludeTasks)(new Set([{ project: context.projectName, target: context.targetName }]), context.projectGraph.nodes, new Set(), includeDependsOnTasks).forEach((task) => {
50
50
  if (task) {
51
51
  args.push('--exclude-task', task);
52
52
  }
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): Promise<void>;
3
+ //# sourceMappingURL=change-plugin-version-0-1-18.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"change-plugin-version-0-1-18.d.ts","sourceRoot":"","sources":["../../../../../../packages/gradle/src/migrations/22-7-0/change-plugin-version-0-1-18.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAc,MAAM,YAAY,CAAC;AAO9C,wBAA8B,MAAM,CAAC,IAAI,EAAE,IAAI,iBAgB9C"}
@@ -0,0 +1,23 @@
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
+ const gradle_project_graph_plugin_utils_1 = require("../../generators/init/gradle-project-graph-plugin-utils");
7
+ const version_catalog_ast_utils_1 = require("../../utils/version-catalog-ast-utils");
8
+ /* Change the plugin version to 0.1.18
9
+ */
10
+ async function update(tree) {
11
+ const nxJson = (0, devkit_1.readNxJson)(tree);
12
+ if (!nxJson) {
13
+ return;
14
+ }
15
+ if (!(0, has_gradle_plugin_1.hasGradlePlugin)(tree)) {
16
+ return;
17
+ }
18
+ const gradlePluginVersionToUpdate = '0.1.18';
19
+ // Update version in version catalogs using AST-based approach to preserve formatting
20
+ await (0, version_catalog_ast_utils_1.updateNxPluginVersionInCatalogsAst)(tree, gradlePluginVersionToUpdate);
21
+ // Then update in build.gradle(.kts) files
22
+ await (0, gradle_project_graph_plugin_utils_1.addNxProjectGraphPlugin)(tree, gradlePluginVersionToUpdate);
23
+ }
@@ -1,4 +1,4 @@
1
1
  export declare const nxVersion: any;
2
2
  export declare const gradleProjectGraphPluginName = "dev.nx.gradle.project-graph";
3
- export declare const gradleProjectGraphVersion = "0.1.17";
3
+ export declare const gradleProjectGraphVersion = "0.1.18";
4
4
  //# sourceMappingURL=versions.d.ts.map
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.gradleProjectGraphVersion = exports.gradleProjectGraphPluginName = exports.nxVersion = void 0;
4
4
  exports.nxVersion = require('../../package.json').version;
5
5
  exports.gradleProjectGraphPluginName = 'dev.nx.gradle.project-graph';
6
- exports.gradleProjectGraphVersion = '0.1.17';
6
+ exports.gradleProjectGraphVersion = '0.1.18';
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=publish-maven.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"publish-maven.d.ts","sourceRoot":"","sources":["../../../../packages/gradle/project-graph/publish-maven.ts"],"names":[],"mappings":""}
@@ -1,104 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const axios_1 = tslib_1.__importDefault(require("axios"));
5
- const fs = tslib_1.__importStar(require("fs"));
6
- const form_data_1 = tslib_1.__importDefault(require("form-data"));
7
- function parseArgs() {
8
- const args = process.argv.slice(2);
9
- const result = {};
10
- args.forEach((arg) => {
11
- const [key, value] = arg.replace(/^--/, '').split('=');
12
- result[key] = value;
13
- });
14
- return result;
15
- }
16
- async function publishToMavenApi(username, password, deploymentZipPath = 'deployment.zip') {
17
- const token = Buffer.from(`${username}:${password}`).toString('base64');
18
- console.log(`📦 Publishing to Maven Central...`);
19
- const url = 'https://central.sonatype.com/api/v1/publisher/upload';
20
- const form = new form_data_1.default();
21
- form.append('bundle', fs.createReadStream(deploymentZipPath));
22
- let uploadId;
23
- try {
24
- const response = await axios_1.default.post(url, form, {
25
- headers: {
26
- Authorization: `Basic ${token}`,
27
- ...form.getHeaders(),
28
- },
29
- });
30
- uploadId = response.data.toString().trim();
31
- console.log(`✅ Upload ID: ${uploadId}`);
32
- }
33
- catch (err) {
34
- console.error('🚫 Upload failed:', err.response?.data || err.message);
35
- process.exit(1);
36
- }
37
- let currentStatus = await getUploadStatus(uploadId, token);
38
- if (['PENDING', 'VALIDATING', 'PUBLISHING'].includes(currentStatus)) {
39
- currentStatus = await retryUntilValidatedOrPublished(currentStatus, uploadId, token);
40
- }
41
- if (!['VALIDATED', 'PUBLISHED'].includes(currentStatus)) {
42
- console.error(`🚫 Upload failed with final status: ${currentStatus}`);
43
- process.exit(1);
44
- }
45
- console.log(`📦 Upload is ${currentStatus}, proceeding to deploy...`);
46
- if (currentStatus === 'PUBLISHED') {
47
- console.log('✅ Already published, skipping deployment.');
48
- return;
49
- }
50
- const deployUrl = `https://central.sonatype.com/api/v1/publisher/deployment/${uploadId}`;
51
- try {
52
- const deployRes = await axios_1.default.post(deployUrl, null, {
53
- headers: { Authorization: `Basic ${token}` },
54
- });
55
- console.log(`🚀 Deployment response: ${deployRes.data}`);
56
- }
57
- catch (err) {
58
- console.error('🚫 Deployment failed:', err.response?.data || err.message);
59
- process.exit(1);
60
- }
61
- }
62
- async function getUploadStatus(uploadId, token) {
63
- const url = `https://central.sonatype.com/api/v1/publisher/status?id=${uploadId}`;
64
- try {
65
- const response = await axios_1.default.post(url, null, {
66
- headers: { Authorization: `Basic ${token}` },
67
- });
68
- const state = response.data.deploymentState;
69
- console.log(`📡 Current deployment state: ${state}`);
70
- return state;
71
- }
72
- catch (err) {
73
- console.error('🚫 Failed to get status:', err.response?.data || err.message);
74
- return 'FAILED';
75
- }
76
- }
77
- async function retryUntilValidatedOrPublished(currentStatus, uploadId, token, retries = 10, delay = 10_000) {
78
- for (let i = 0; i < retries; i++) {
79
- console.log(`🔁 Checking status (attempt ${i + 1}/${retries})...`);
80
- await sleep(delay);
81
- currentStatus = await getUploadStatus(uploadId, token);
82
- if (['VALIDATED', 'PUBLISHED', 'FAILED'].includes(currentStatus))
83
- break;
84
- }
85
- return currentStatus;
86
- }
87
- function sleep(ms) {
88
- return new Promise((resolve) => setTimeout(resolve, ms));
89
- }
90
- // Entry
91
- (async function main() {
92
- let { username, password, deploymentZipPath } = parseArgs();
93
- username = username || process.env.MAVEN_USERNAME;
94
- password = password || process.env.MAVEN_PASSWORD;
95
- if (!username || !password) {
96
- console.error('❌ Missing MAVEN_USERNAME or MAVEN_PASSWORD');
97
- process.exit(1);
98
- }
99
- if (!deploymentZipPath) {
100
- console.error('❌ Missing required --deploymentZipPath argument');
101
- process.exit(1);
102
- }
103
- await publishToMavenApi(username, password, deploymentZipPath);
104
- })();