Skip to content

Commit

Permalink
fix(gradle): fix gradle app deps (nrwl#27865)
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 nrwl#27819
  • Loading branch information
xiongemi authored Sep 11, 2024
1 parent 5784b88 commit 2eb5592
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
23 changes: 16 additions & 7 deletions e2e/gradle/src/gradle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ describe('Gradle', () => {
expect(projects).toContain('utilities');
expect(projects).toContain(gradleProjectName);

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

checkFilesExist(
Expand All @@ -43,9 +45,14 @@ describe('Gradle', () => {
`utilities/build/libs/utilities.jar`
);

expect(() => {
runCLI(`build ${gradleProjectName}`, { verbose: true });
}).not.toThrow();
buildOutput = runCLI(`build ${gradleProjectName}`, { verbose: true });
// root project depends on app, list and utilities
expect(buildOutput).toContain('nx run app:build');
expect(buildOutput).toContain(':app:classes');
expect(buildOutput).toContain('nx run list:build');
expect(buildOutput).toContain(':list:classes');
expect(buildOutput).toContain('nx run utilities:build');
expect(buildOutput).toContain(':utilities:classes');
});

it('should track dependencies for new app', () => {
Expand Down Expand Up @@ -85,9 +92,11 @@ dependencies {
return content;
}
);
expect(() => {
runCLI('build app2', { verbose: true });
}).not.toThrow();

let buildOutput = runCLI('build app2', { verbose: true });
// app2 depends on app
expect(buildOutput).toContain('nx run app:build');
expect(buildOutput).toContain(':app:classes');
});
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ antBuilderFactory: org.gradle.api.internal.project.DefaultAntBuilderFactory@5a5e
artifacts: org.gradle.api.internal.artifacts.dsl.DefaultArtifactHandler_Decorated@3793af5a
asDynamicObject: DynamicObject for root project 'My Application'
baseClassLoaderScope: org.gradle.api.internal.initialization.DefaultClassLoaderScope@4dc8adab
buildDir: /Users/emily/code/tmp/nx-android/build
buildFile: /Users/emily/code/tmp/nx-android/build.gradle
buildDir: /tmp/nx-android/build
buildFile: /tmp/nx-android/build.gradle
buildPath: :
buildScriptSource: org.gradle.groovy.scripts.TextResourceScriptSource@622acc87
buildTreePath: :
Expand Down Expand Up @@ -73,13 +73,13 @@ plugins: [org.gradle.api.plugins.HelpTasksPlugin$Inject@611c939a, org.gradle.bui
processOperations: org.gradle.process.internal.DefaultExecActionFactory$DecoratingExecActionFactory@2bcbdbd2
project: root project 'My Application'
projectConfigurator: org.gradle.api.internal.project.BuildOperationCrossProjectConfigurator@e136ccb
projectDir: /Users/emily/code/tmp/nx-android
projectDir: /tmp/nx-android
projectEvaluationBroadcaster: ProjectEvaluationListener broadcast
projectEvaluator: org.gradle.configuration.project.LifecycleProjectEvaluator@4d3e0414
projectPath: :
projectReport: task ':projectReport'
projectReportAll: task ':projectReportAll'
projectReportDir: /Users/emily/code/tmp/nx-android/build/reports/project
projectReportDir: /tmp/nx-android/build/reports/project
projectReportDirName: project
projects: [root project 'My Application']
properties: {...}
Expand All @@ -89,7 +89,7 @@ publicType: org.gradle.api.plugins.ProjectReportsPluginConvention
reporting: extension 'reporting'
repositories: repository container
resources: org.gradle.api.internal.resources.DefaultResourceHandler@3bfc23c4
rootDir: /Users/emily/code/tmp/nx-android
rootDir: /tmp/nx-android
rootProject: root project 'My Application'
rootScript: false
script: false
Expand Down
15 changes: 12 additions & 3 deletions packages/gradle/src/utils/get-gradle-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,16 @@ export function processProjectReports(
absBuildDirPath = line.substring('buildDir: '.length);
}
if (line.startsWith('childProjects: ')) {
const childProjects = line.substring('childProjects: {'.length); // remove curly braces {} around childProjects
const childProjects = line.substring(
'childProjects: {'.length,
line.length - 1
); // remove curly braces {} around childProjects
gradleProjectToChildProjects.set(
gradleProject,
childProjects.split(',').map((c) => c.trim().split('=')[0]) // e.g. get project name from text like "app=project ':app', mylibrary=project ':mylibrary'"
childProjects
.split(',')
.map((c) => c.trim().split('=')[0])
.filter(Boolean) // e.g. get project name from text like "app=project ':app', mylibrary=project ':mylibrary'"
);
}
if (line.includes('Dir: ')) {
Expand Down Expand Up @@ -228,7 +234,10 @@ export function processProjectReports(
gradleFileToOutputDirsMap.set(buildFile, outputDirMap);
gradleFileToGradleProjectMap.set(buildFile, gradleProject);
gradleProjectToProjectName.set(gradleProject, projectName);
gradleProjectNameToProjectRootMap.set(projectName, dirname(buildFile));
gradleProjectNameToProjectRootMap.set(
gradleProject,
dirname(buildFile)
);
}
if (line.endsWith('taskReport')) {
const gradleProject = line.substring(
Expand Down

0 comments on commit 2eb5592

Please sign in to comment.