Skip to content

Commit

Permalink
feat: add plugin dependencies to nx-maven graph (#1343)
Browse files Browse the repository at this point in the history
* feat: add plugin dependencies to nx-maven graph

* build: add pluginManagement use case

* build: work in progress
  • Loading branch information
khalilou88 authored Oct 14, 2024
1 parent 40f62b0 commit b687f25
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
27 changes: 27 additions & 0 deletions packages/nx-maven/src/graph/create-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ export const createDependencies: CreateDependencies = (
results.push(newDependency);
}
}

const pluginDependencies = getPluginDependencyProjects(
project,
projects,
);
for (const pluginDependency of pluginDependencies) {
if (!pluginDependency.skipProject) {
const newDependency = {
source: project.artifactId,
target: pluginDependency.artifactId,
sourceFile: projectSourceFile,
type: DependencyType.static,
};

validateDependency(newDependency, context);
results.push(newDependency);
}
}
}
}
},
Expand Down Expand Up @@ -152,3 +170,12 @@ function getProfileDependencyProjects(
project.profileDependencies.includes(p.artifactId),
);
}

function getPluginDependencyProjects(
project: MavenProjectType,
projects: MavenProjectType[],
) {
return projects.filter((p) =>
project.pluginDependencies.includes(p.artifactId),
);
}
59 changes: 58 additions & 1 deletion packages/nx-maven/src/graph/graph-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { existsSync } from 'fs';
import { InputDefinition } from 'nx/src/config/workspace-json-project-json';
import { workspaceDataDirectory } from 'nx/src/utils/cache-directory';
import * as path from 'path';
import { XmlDocument } from 'xmldoc';
import { XmlDocument, XmlElement } from 'xmldoc';
import {
getArtifactId,
getExpressionValue,
Expand All @@ -37,6 +37,7 @@ export interface MavenProjectType {
projectAbsolutePath: string;
dependencies: (string | undefined)[];
profileDependencies: (string | undefined)[];
pluginDependencies: (string | undefined)[];
parentProjectArtifactId?: string;
aggregatorProjectArtifactId?: string;
properties: PropertyType[];
Expand Down Expand Up @@ -140,6 +141,8 @@ export function addProjects(

const profileDependencies = getProfileDependencyArtifactIds(pomXmlContent);

const pluginDependencies = getPluginDependencyArtifactIds(pomXmlContent);

const properties = getProperties(pomXmlContent);

const projectJsonPath = path.join(projectAbsolutePath, 'project.json');
Expand All @@ -156,6 +159,7 @@ export function addProjects(
projectAbsolutePath: projectAbsolutePath,
dependencies: dependencies,
profileDependencies: profileDependencies,
pluginDependencies: pluginDependencies,
parentProjectArtifactId: parentProjectArtifactId,
aggregatorProjectArtifactId: aggregatorProjectArtifactId,
properties: properties,
Expand Down Expand Up @@ -462,6 +466,59 @@ function getProfileDependencyArtifactIds(pomXml: XmlDocument) {
return results;
}

function getPluginDependencyArtifactIds(pomXml: XmlDocument) {
let results: (string | undefined)[] = [];

const buildXml = pomXml.childNamed('build');
if (buildXml === undefined) {
return [];
}

results = results.concat(
getPluginDependencyArtifactIdsFromPluginsTag(buildXml),
);

const pluginManagementXml = buildXml.childNamed('pluginManagement');

if (pluginManagementXml === undefined) {
return results;
}

results = results.concat(
getPluginDependencyArtifactIdsFromPluginsTag(pluginManagementXml),
);

return results;
}

function getPluginDependencyArtifactIdsFromPluginsTag(xmlElement: XmlElement) {
let results: (string | undefined)[] = [];

const pluginsXml = xmlElement.childNamed('plugins');
if (pluginsXml === undefined) {
return [];
}

const pluginXmlArray = pluginsXml.childrenNamed('plugin');

for (const profileXml of pluginXmlArray) {
const dependenciesXml = profileXml.childNamed('dependencies');
if (dependenciesXml === undefined) {
continue;
}

const pluginDependencyArtifactIds = dependenciesXml
.childrenNamed('dependency')
.map((dependencyXmlElement) => {
return dependencyXmlElement.childNamed('artifactId')?.val;
});

results = results.concat(pluginDependencyArtifactIds);
}

return results;
}

export function getOutputDirLocalRepo(
localRepositoryPath: string,
groupId: string,
Expand Down

0 comments on commit b687f25

Please sign in to comment.