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

init.gradle: Ignore BOM dependencies when comparing dependency trees #6092

Conversation

nnobelis
Copy link
Member

When comparing dependency trees, the count of sub dependencies should not include BOM dependencies, since they are skipped by the fetchDependency function.
This solves a bug where an Android project shipping 'androidx.appcompat:appcompat:1.5.1' would hang indefinitely. This is because, for instance, 'kotlinx-coroutines-android:1.6.1' depends on 'kotlinx-coroutines-core:1.6.1, kotlin-stdlib-jdk8:1.6.0 and kotlinx-coroutines-bom:1.6.1'. Since no ORT dependency is created for 'kotlinx-coroutines-bom' because it's a BOM file, it should also not be taken in account when comparing dependency trees. Otherwise, comparison would always fail, leading to a cache miss and overgrowth of the latter.

Signed-off-by: Nicolas Nobelis [email protected]

@nnobelis nnobelis requested a review from a team as a code owner November 17, 2022 16:34
mnonnenmacher
mnonnenmacher previously approved these changes Nov 18, 2022
@sschuberth
Copy link
Member

@mpbecker and @pirvudoru, could help confirming whether this fixes your issues described here and here, respectively?

@@ -251,7 +251,7 @@ class AbstractDependencyTreePlugin<T> implements Plugin<T> {
/**
* Return true if the provided DependencyResult represents an imported Maven BOM.
*/
private boolean isBom(DependencyResult dependencyResult) {
private static boolean isBom(DependencyResult dependencyResult) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Unrelated change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, expanding the diffs shows that it's not unrelated as isBom is called from the static dependencyTreeEquals now.

@@ -394,7 +394,8 @@ class AbstractDependencyTreePlugin<T> implements Plugin<T> {

def resultDependencies = dependencyResult instanceof ResolvedDependencyResult ?
dependencyResult.selected.dependencies : [] as Set<DependencyResult>
if (dependency.dependencies.size() != resultDependencies.size()) {
// Ignore the BOM dependencies for calculating the count since they are skipped by `fetchDependency`.
if (dependency.dependencies.size() != resultDependencies.findAll { !isBom(it) }.size()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could we use count { !isBom(it) } here?

When comparing dependency trees, the count of sub dependencies should
not include BOM dependencies, since they are skipped by the
`fetchDependency` function.
This solves a bug where an Android project shipping
'androidx.appcompat:appcompat:1.5.1' would hang indefinitely. This is
because, for instance, 'kotlinx-coroutines-android:1.6.1' depends on
'kotlinx-coroutines-core:1.6.1, kotlin-stdlib-jdk8:1.6.0 and
kotlinx-coroutines-bom:1.6.1'. Since no ORT dependency is created for
'kotlinx-coroutines-bom' because it's a BOM file, it should also not be
taken in account when comparing dependency trees. Otherwise, comparison
would always fail, leading to a cache miss and overgrowth of the latter.

Signed-off-by: Nicolas Nobelis <[email protected]>
@MarcelBochtler MarcelBochtler merged commit dba5140 into oss-review-toolkit:main Nov 18, 2022
@MarcelBochtler MarcelBochtler deleted the nnobelis/fix_grade_android_dependencies branch November 18, 2022 12:14
@sschuberth sschuberth added the release notes Changes that should be mentioned in release notes label Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes Changes that should be mentioned in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants