Skip to content

Commit

Permalink
fix(gradle): fix find root for projects (#27651)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #

(cherry picked from commit 6cb0720)
  • Loading branch information
xiongemi authored and FrozenPandaz committed Aug 28, 2024
1 parent 9c964a1 commit 90ebb22
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion e2e/gradle/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "e2e/gradle",
"projectType": "application",
"implicitDependencies": ["eslint"],
"implicitDependencies": ["gradle"],
"// targets": "to see all targets run: nx show project e2e-gradle --web",
"targets": {}
}
10 changes: 5 additions & 5 deletions e2e/gradle/src/gradle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ describe('Gradle', () => {

const buildOutput = runCLI('build app', { verbose: true });
// app depends on list and utilities
expect(buildOutput).toContain('nx run list:build');
expect(buildOutput).toContain('nx run utilities:build');
expect(buildOutput).toContain(':list:classes');
expect(buildOutput).toContain(':utilities:classes');

checkFilesExist(
`app/build/libs/app.jar`,
Expand Down Expand Up @@ -85,9 +85,9 @@ dependencies {
return content;
}
);
const buildOutput = runCLI('build app2', { verbose: true });
// app2 depends on app
expect(buildOutput).toContain('nx run app:build');
expect(() => {
runCLI('build app2', { verbose: true });
}).not.toThrow();
});
}
);
Expand Down
17 changes: 13 additions & 4 deletions packages/gradle/src/plugin/dependencies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ describe('processGradleDependencies', () => {
'app',
{
projects: {
'utilities/number-utils': {
'number-utils': {
root: 'utilities/number-utils',
name: 'number-utils',
},
'utilities/string-utils': {
'string-utils': {
root: 'utilities/string-utils',
name: 'string-utils',
},
utilities: {
root: 'utilities',
name: 'utilities',
},
},
} as any,
dependencies
Expand Down Expand Up @@ -68,13 +74,16 @@ describe('processGradleDependencies', () => {
'app',
{
projects: {
'utilities/number-utils': {
'number-utils': {
root: 'utilities/number-utils',
name: 'number-utils',
},
'utilities/string-utils': {
'string-utils': {
root: 'utilities/string-utils',
name: 'string-utils',
},
utilities: {
root: 'utilities',
name: 'utilities',
},
},
Expand Down
12 changes: 8 additions & 4 deletions packages/gradle/src/plugin/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export const createDependencies: CreateDependencies = async (

for (const gradleFile of gradleFiles) {
const gradleProject = gradleFileToGradleProjectMap.get(gradleFile);
const projectName = context.projects[dirname(gradleFile)].name;
const projectName = Object.values(context.projects).find(
(project) => project.root === dirname(gradleFile)
)?.name;
const depsFile = buildFileToDepsMap.get(gradleFile);

if (projectName && depsFile) {
Expand Down Expand Up @@ -125,11 +127,13 @@ export function processGradleDependencies(
const targetProjectRoot = gradleProjectNameToProjectRoot.get(
gradleProjectName
) as string;
const target = context.projects[targetProjectRoot]?.name;
if (target) {
const targetProjectName = Object.values(context.projects).find(
(project) => project.root === targetProjectRoot
)?.name;
if (targetProjectName) {
const dependency: RawProjectGraphDependency = {
source: sourceProjectName,
target,
target: targetProjectName,
type: DependencyType.static,
sourceFile: gradleFile,
};
Expand Down

0 comments on commit 90ebb22

Please sign in to comment.