Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix issues when building the graph #224

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 3 additions & 4 deletions packages/nx-quarkus/src/utils/plugin-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export function getProjectTypeAndTargetsFromFile(
);
projectType = hasMavenPlugin(
root,
'org.springframework.boot',
'spring-boot-maven-plugin'
'${quarkus.platform.group-id}',
'quarkus-maven-plugin'
)
? 'application'
: 'library';
Expand All @@ -56,8 +56,7 @@ export function getProjectTypeAndTargetsFromFile(
);
skipFormat = hasGradlePlugin(projectContent, SPOTLESS_GRADLE_PLUGIN_ID);
projectType =
getGradlePlugin(projectContent, 'org.springframework.boot').applied ===
false
getGradlePlugin(projectContent, 'io.quarkus')?.applied === false
? 'library'
: 'application';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-spring-boot/src/utils/plugin-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function getProjectTypeAndTargetsFromFile(
);
skipFormat = hasGradlePlugin(projectContent, SPOTLESS_GRADLE_PLUGIN_ID);
projectType =
getGradlePlugin(projectContent, 'org.springframework.boot').applied ===
getGradlePlugin(projectContent, 'org.springframework.boot')?.applied ===
false
? 'library'
: 'application';
Expand Down
Loading