diff --git a/packages/gradle/src/plugin/nodes.ts b/packages/gradle/src/plugin/nodes.ts index 62705c6980..81613eb38b 100644 --- a/packages/gradle/src/plugin/nodes.ts +++ b/packages/gradle/src/plugin/nodes.ts @@ -1,6 +1,7 @@ import { CreateNodes, CreateNodesContext, + ProjectConfiguration, TargetConfiguration, readJsonFile, writeJsonFile, @@ -13,7 +14,6 @@ import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory'; import { getGradleBinaryPath } from '../utils/exec-gradle'; import { getGradleReport } from '../utils/get-gradle-report'; -const nonCacheableGradleTaskTypes = new Set(['Application']); const dependsOnMap = { build: ['^build', 'classes'], test: ['classes'], @@ -37,12 +37,20 @@ const targetsCache = existsSync(cachePath) ? readTargetsCache() : {}; export const calculatedTargets: Record< string, - { name: string; targets: Record } + { + name: string; + targets: Record; + targetGroups: Record; + } > = {}; function readTargetsCache(): Record< string, - { name: string; targets: Record } + { + name: string; + targets: Record; + targetGroups: Record; + } > { return readJsonFile(cachePath); } @@ -50,7 +58,11 @@ function readTargetsCache(): Record< export function writeTargetsToCache( targets: Record< string, - { name: string; targets: Record } + { + name: string; + targets: Record; + targetGroups: Record; + } > ) { writeJsonFile(cachePath, targets); @@ -74,7 +86,12 @@ export const createNodes: CreateNodes = [ calculatedTargets[hash] = targetsCache[hash]; return { projects: { - [projectRoot]: targetsCache[hash], + [projectRoot]: { + ...targetsCache[hash], + metadata: { + technologies: ['gradle'], + }, + }, }, }; } @@ -111,7 +128,7 @@ export const createNodes: CreateNodes = [ string >; - const targets = createGradleTargets( + const { targets, targetGroups } = createGradleTargets( tasks, projectRoot, options, @@ -121,15 +138,20 @@ export const createNodes: CreateNodes = [ calculatedTargets[hash] = { name: projectName, targets, + targetGroups, + }; + + const project: Omit = { + name: projectName, + targets, + metadata: { + technologies: ['gradle'], + }, }; return { projects: { - [projectRoot]: { - root: projectRoot, - name: projectName, - targets, - }, + [projectRoot]: project, }, }; } catch (e) { @@ -145,10 +167,14 @@ function createGradleTargets( options: GradlePluginOptions | undefined, context: CreateNodesContext, outputDirs: Map -): Record { +): { + targetGroups: Record; + targets: Record; +} { const inputsMap = createInputsMap(context); const targets: Record = {}; + const targetGroups: Record = {}; for (const task of tasks) { const targetName = options?.[`${task.name}TargetName`] ?? task.name; @@ -158,13 +184,17 @@ function createGradleTargets( options: { cwd: projectRoot, }, - cache: !nonCacheableGradleTaskTypes.has(task.type), + cache: !!outputs, inputs: inputsMap[task.name], outputs: outputs ? [outputs] : undefined, dependsOn: dependsOnMap[task.name], }; + if (!targetGroups[task.type]) { + targetGroups[task.type] = []; + } + targetGroups[task.type].push(task.name); } - return targets; + return { targetGroups, targets }; } function createInputsMap(