Skip to content

Commit

Permalink
fix: fix dependencies from modules not properly created when building…
Browse files Browse the repository at this point in the history
… project graph
  • Loading branch information
tinesoft committed Apr 29, 2024
1 parent 50ed737 commit 06e0370
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/common-jvm/src/lib/utils/gradle-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ export function getCoordinatesForGradleProjet(cwd: string): {
/rootProject\.name\s*=\s*['"]([^"']+)['"]/
)?.[1];
}
artifactId = artifactId ?? name; // use the folder name as default if stil undefined
artifactId = artifactId ?? name; // use the folder name as default if still undefined

if (hasGradleBuildFile(cwd)) {
const buildGradle = getProjectFileContent({ root: cwd }, `build${ext}`);
Expand Down
37 changes: 27 additions & 10 deletions packages/common-jvm/src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export function getJvmPackageInfo(project: { root: string }): PackageInfo {
packageId: `${groupId}:${artifactId}`,
packageFile: 'pom.xml',
dependencies,
modules: modules.map((mod) => `${groupId}:${mod}`),
modules: modules.map((module) => `${project.root}/${module}`),
};
}

Expand All @@ -225,29 +225,46 @@ export function getJvmPackageInfo(project: { root: string }): PackageInfo {
const id = match?.groups?.['id'];
if (id) {
// project dependencies start with ':', we prepend the groupId to it
dependencyIds.push(id.startsWith(':') ? `${groupId}${id}` : id);
dependencyIds.push(
id.startsWith(':')
? `${project.root}${id.replaceAll(':', '/')}`
: id
);
}
} while (match);
}

const dependencies: PackageInfo[] = dependencyIds.map((depId) => {
return { packageId: depId, packageFile: `build${ext}` };
let depGroupId: string | null | undefined;
let depArtifactId: string | null | undefined;
if (depId.startsWith(':')) {
// project dependencies start with ':'
const coordinates = getCoordinatesForGradleProjet(
`${project.root}/${depId.replaceAll(':', '/')}`
);
depGroupId = coordinates.groupId;
depArtifactId = coordinates.artifactId;
} else {
[depGroupId, depArtifactId] = depId.split(':');
}

return {
packageId: `${depGroupId}:${depArtifactId}`,
packageFile: `build${ext}`,
};
});

const modules = getGradleModules(project.root);

const offsetFromRoot = getPathFromParentModule(project.root);
const pkgId = offsetFromRoot
? offsetFromRoot.replaceAll('/', ':')
: artifactId;

return {
packageId: `${groupId}:${pkgId}`,
packageId: `${groupId}:${artifactId}`,
packageFile: hasGradleSettingsFile(project.root)
? `settings${ext}`
: `build${ext}`,
dependencies,
modules: modules.map((mod) => `${groupId}:${mod}`),
modules: modules.map(
(module) => `${project.root}/${module.replaceAll(':', '/')}`
),
};
}

Expand Down
9 changes: 4 additions & 5 deletions packages/common/src/lib/workspace/project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ function getDependenciesForProject(
const sourceProjectRoot = getProjectRootFromFile(filePath);
const sourcePkgInfo = workspace.projects[sourceProjectRoot];

if(!sourcePkgInfo)
return dependencies;
if (!sourcePkgInfo) return dependencies;

sourcePkgInfo.dependencies?.forEach((depPkgInfo) => {
const targetProjectName = workspace.packages[depPkgInfo.packageId];
Expand All @@ -93,12 +92,12 @@ function getDependenciesForProject(
});

sourcePkgInfo.modules?.forEach((moduleId) => {
const depProjectName = workspace.packages[moduleId];
const depProject = workspace.projects[moduleId];

if (depProjectName) {
if (depProject) {
dependencies.push({
source: sourceProjectName,
target: depProjectName,
target: workspace.packages[depProject.packageId],
type: DependencyType.static,
sourceFile: joinPathFragments(
sourceProjectRoot,
Expand Down

0 comments on commit 06e0370

Please sign in to comment.