-
-
Notifications
You must be signed in to change notification settings - Fork 155
fix: make GraphViewTask sensitive to new transitive project edges. #1780
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
Merged
autonomousapps
merged 3 commits into
main
from
andrew/graphview-project-edge-cache-test
Jul 16, 2026
+222
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/functionalTest/groovy/com/autonomousapps/jvm/GraphViewProjectEdgeCacheSpec.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Copyright (c) 2026. Tony Robalik. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| package com.autonomousapps.jvm | ||
|
|
||
| import com.autonomousapps.internal.OutputPathsKt | ||
| import com.autonomousapps.jvm.projects.GraphViewProjectEdgeCacheProject | ||
|
|
||
| import static com.autonomousapps.kit.truth.BuildTaskSubject.buildTasks | ||
| import static com.autonomousapps.utils.Runner.build | ||
| import static com.google.common.truth.Truth.assertAbout | ||
| import static com.google.common.truth.Truth.assertThat | ||
|
|
||
| final class GraphViewProjectEdgeCacheSpec extends AbstractJvmSpec { | ||
|
|
||
| def "graphViewTask is sensitive to new transitive project edges (#gradleVersion)"() { | ||
| given: | ||
| def project = new GraphViewProjectEdgeCacheProject() | ||
| gradleProject = project.gradleProject | ||
| def task = ':consumer:graphViewMain' | ||
|
|
||
| when: 'First build, without the direct -> transitive edge' | ||
| def result = build(gradleVersion, gradleProject.rootDir, ':buildHealth', '--build-cache') | ||
| def graphCompilePath = OutputPathsKt.getGraphCompilePath('main') | ||
| def graphOutput = gradleProject.singleArtifact('consumer', graphCompilePath).asFile | ||
|
|
||
| then: 'Task executed and transitive is not in the graph' | ||
| assertAbout(buildTasks()).that(result.task(task)).succeeded() | ||
| assertThat(graphOutput.text).doesNotContain(':transitive') | ||
|
|
||
| when: 'Second build, after the direct project adds an api dependency on transitive' | ||
| result = build(gradleVersion, gradleProject.rootDir, 'clean', ':buildHealth', '--build-cache', '-Dedge=true') | ||
|
|
||
| then: 'Task executed (not FROM_CACHE) and transitive is in the graph' | ||
| assertAbout(buildTasks()).that(result.task(task)).succeeded() | ||
| assertThat(graphOutput.text).contains(':transitive') | ||
|
|
||
| where: | ||
| gradleVersion << gradleVersions() | ||
| } | ||
|
|
||
| def "stale project graph does not suppress dependency advice (#gradleVersion)"() { | ||
| given: | ||
| def project = new GraphViewProjectEdgeCacheProject() | ||
| gradleProject = project.gradleProject | ||
|
|
||
| when: 'First build, without the direct -> transitive edge' | ||
| build(gradleVersion, gradleProject.rootDir, ':buildHealth', '--build-cache') | ||
|
|
||
| then: 'There is no advice' | ||
| assertThat(actualProjectAdvice('consumer').dependencyAdvice).isEmpty() | ||
|
|
||
| when: 'Second build, after the direct project adds an api dependency on transitive' | ||
| build(gradleVersion, gradleProject.rootDir, 'clean', ':buildHealth', '--build-cache', '-Dedge=true') | ||
|
|
||
| then: 'Advises declaring the used transitive dependency directly' | ||
| assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth) | ||
|
|
||
| where: | ||
| gradleVersion << gradleVersions() | ||
| } | ||
| } |
130 changes: 130 additions & 0 deletions
130
...tionalTest/groovy/com/autonomousapps/jvm/projects/GraphViewProjectEdgeCacheProject.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| // Copyright (c) 2026. Tony Robalik. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| package com.autonomousapps.jvm.projects | ||
|
|
||
| import com.autonomousapps.AbstractProject | ||
| import com.autonomousapps.kit.GradleProject | ||
| import com.autonomousapps.kit.Source | ||
| import com.autonomousapps.kit.gradle.SettingsScript | ||
| import com.autonomousapps.model.Advice | ||
| import com.autonomousapps.model.ProjectAdvice | ||
|
|
||
| import static com.autonomousapps.AdviceHelper.* | ||
| import static com.autonomousapps.kit.gradle.Dependency.implementation | ||
|
|
||
| final class GraphViewProjectEdgeCacheProject extends AbstractProject { | ||
|
|
||
| final GradleProject gradleProject | ||
|
|
||
| GraphViewProjectEdgeCacheProject() { | ||
| this.gradleProject = build() | ||
| } | ||
|
|
||
| private GradleProject build() { | ||
| return newGradleProjectBuilder() | ||
| .withRootProject { s -> | ||
| s.settingsScript = new SettingsScript().tap { | ||
| // Since this test exercises the build cache, we can't rely on the default location | ||
| additions = """ | ||
| buildCache { | ||
| local { | ||
| directory = new File(rootDir, 'build-cache') | ||
| } | ||
| }""".stripIndent() | ||
| } | ||
| } | ||
| .withSubproject('consumer') { s -> | ||
| s.sources = CONSUMER_SOURCE | ||
| s.withBuildScript { bs -> | ||
| bs.plugins = kotlin | ||
| bs.dependencies(implementation(':direct')) | ||
| bs.withGroovy("""\ | ||
| if (providers.systemProperty('edge').present) { | ||
| sourceSets.main.kotlin.srcDir('src/edge/kotlin') | ||
| }""".stripIndent()) | ||
| } | ||
| } | ||
| .withSubproject('direct') { s -> | ||
| s.sources = DIRECT_SOURCE | ||
| s.withBuildScript { bs -> | ||
| bs.plugins = kotlin | ||
| // The system property models an upstream change adding a project edge: the | ||
| // consumer's own build script and declarations are untouched by it. | ||
| bs.withGroovy("""\ | ||
| if (providers.systemProperty('edge').present) { | ||
| dependencies { | ||
| api project(':transitive') | ||
| } | ||
| }""") | ||
| } | ||
| } | ||
| .withSubproject('transitive') { s -> | ||
| s.sources = TRANSITIVE_SOURCE | ||
| s.withBuildScript { bs -> | ||
| bs.plugins = kotlin | ||
| } | ||
| } | ||
| .write() | ||
| } | ||
|
|
||
| private static final List<Source> CONSUMER_SOURCE = [ | ||
| Source.kotlin( | ||
| '''\ | ||
| package com.example | ||
|
|
||
| import com.example.direct.Direct | ||
|
|
||
| class Main { | ||
| private val direct = Direct() | ||
| }'''.stripIndent() | ||
| ).build(), | ||
| Source.kotlin( | ||
| '''\ | ||
| package com.example | ||
|
|
||
| import com.example.transitive.Transitive | ||
|
|
||
| class UsesTransitive { | ||
| private val transitive = Transitive() | ||
| }'''.stripIndent() | ||
| ) | ||
| .withSourceSet('edge') | ||
| .build(), | ||
| ] | ||
|
|
||
| private static final List<Source> DIRECT_SOURCE = [ | ||
| Source.kotlin( | ||
| '''\ | ||
| package com.example.direct | ||
|
|
||
| class Direct'''.stripIndent() | ||
| ).build(), | ||
| ] | ||
|
|
||
| private static final List<Source> TRANSITIVE_SOURCE = [ | ||
| Source.kotlin( | ||
| '''\ | ||
| package com.example.transitive | ||
|
|
||
| class Transitive'''.stripIndent() | ||
| ).build(), | ||
| ] | ||
|
|
||
| Set<ProjectAdvice> actualBuildHealth() { | ||
| return actualProjectAdvice(gradleProject) | ||
| } | ||
|
|
||
| private final Set<Advice> consumerAdvice = [ | ||
| Advice.ofAdd(projectCoordinates(':transitive'), 'implementation') | ||
| ] | ||
|
|
||
| private static Set<Advice> directAdvice = [ | ||
| Advice.ofRemove(projectCoordinates(':transitive'), 'api') | ||
| ] | ||
|
|
||
| final Set<ProjectAdvice> expectedBuildHealth = [ | ||
| projectAdviceForDependencies(':consumer', consumerAdvice), | ||
| projectAdviceForDependencies(':direct', directAdvice), | ||
| emptyProjectAdviceFor(':transitive'), | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made this a
Set<String>instead of aSet<ResolvedComponentResult>. AFAIK,ResolvedComponentResulthas no realhashCode()function, and so has no legitimate set semantics.