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(gradle): fix gradle app deps #27865

Merged
merged 1 commit into from
Sep 11, 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
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