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

All dependencies are assigned to the settings.gradle.kts file #80

Open
JLLeitschuh opened this issue Nov 6, 2023 · 10 comments
Open

All dependencies are assigned to the settings.gradle.kts file #80

JLLeitschuh opened this issue Nov 6, 2023 · 10 comments
Labels
enhancement New feature or request

Comments

@JLLeitschuh
Copy link
Contributor

JLLeitschuh commented Nov 6, 2023

Looking at the self-test results, all of the dependencies are being bound to the settings.gradle.kts file instead of binding the dependencies to the respective subproject's build.gradle.kts file.

https://github.com/gradle/github-dependency-graph-gradle-plugin/network/dependencies

For example, search for junit: https://github.com/gradle/github-dependency-graph-gradle-plugin/network/dependencies?q=junit

This dependency could be traced to either of these two locations:

However, neither of these files are linked to in the GitHub UI

@bigdaz
Copy link
Member

bigdaz commented Nov 6, 2023

FYI here's the commit that flattened the model to a single "manifest" for the entire build invocation.

Ideally, each resolved dependency version could be traced to the one (or several) places where it is declared. Unfortunately Gradle makes this very difficult to determine, and simply linking to the subproject that resolves a dependency (the previous behaviour) wasn't particular helpful if the version is defined elsewhere, like in a plugin or a .toml file.

BUT, linking the dependency to each subproject has the major downside of creating many more dependabot alerts for the project when this version needed upgrading. When working with real-world projects this made the Dependency Graph support much less useful, since the 100s of alerts generated led to users not trusting the tool.

So until we can reliably link a dependency version to the source file where it is defined, I'd prefer to point to the entire Gradle build (either settings.gradle or the root build.gradle), rather than try to guess a more specific location which might be incorrect.

@bigdaz
Copy link
Member

bigdaz commented Nov 6, 2023

BUT, linking the dependency to each subproject has the major downside of creating many more dependabot alerts for the project when this version needed upgrading. When working with real-world projects this made the Dependency Graph support much less useful, since the 100s of alerts generated led to users not trusting the tool.

To clarify this: imaging a Gradle build with 100 Java subprojects, and each subproject applies a convention plugin to configure the version of Junit used. In this case, we should be linking the junit dependency to the plugin sources as the single location where the version is defined.

But since we don't have a mechanism to do this, I don't think we should link this junit version to each of the subprojects that applies that plugin. Instead, we simply link the junit version to the entire Gradle build, relying on the users to determine which exact source file needs to be updated.

@JLLeitschuh
Copy link
Contributor Author

BUT, linking the dependency to each subproject has the major downside of creating many more dependabot alerts for the project when this version needed upgrading. When working with real-world projects this made the Dependency Graph support much less useful, since the 100s of alerts generated led to users not trusting the tool.

Friendly ping to @jhutchings1 This seems like a bug, and/or a bad user experience for this feature.

Ideally, each resolved dependency version could be traced to the one (or several) places where it is declared. Unfortunately Gradle makes this very difficult to determine, and simply linking to the subproject that resolves a dependency (the previous behaviour) wasn't particular helpful if the version is defined elsewhere, like in a plugin or a .toml file.

This seems like something that could be tracked if the .toml file generated a richer Dependency object that included this information regarding declaring file, and this information was exposed all the way through the resolution event API.

Instead, we simply link the junit version to the entire Gradle build, relying on the users to determine which exact source file needs to be updated.

This seems like a reasonable "guess" could be made for a majority of cases, rather than always being incorrect by just using the settings.gradle file. This would be the principle of least surprise IMHO.

@JLLeitschuh
Copy link
Contributor Author

JLLeitschuh commented Nov 7, 2023

So until we can reliably link a dependency version to the source file where it is defined, I'd prefer to point to the entire Gradle build (either settings.gradle or the root build.gradle), rather than try to guess a more specific location which might be incorrect.

🤔 I see your rationale, but I don't entirely agree. The dependency is tied to a specific subproject, and each subproject has a dedicated build.gradle file. Even if the dependency isn't declared in the build.gradle, it's still the file where that particular dependency is "managed" because it's the build.gradle for that project, and thus, the resolving configurations.

@jhutchings1
Copy link

BUT, linking the dependency to each subproject has the major downside of creating many more dependabot alerts for the project when this version needed upgrading. When working with real-world projects this made the Dependency Graph support much less useful, since the 100s of alerts generated led to users not trusting the tool.

Friendly ping to @jhutchings1 This seems like a bug, and/or a bad user experience for this feature.

Understood that this isn't ideal behavior, but we're not anticipating making any changes to the behavior of the API at this time.

@bigdaz bigdaz added the enhancement New feature or request label Apr 5, 2024
@madisp
Copy link

madisp commented Apr 22, 2024

adding to the discussion here - medium sized Gradle build, 49 modules, 1 extra included build. Dependency analysis is cool, but I have no clue where the deps are coming from as all of them say settings.gradle.kts. I would much rather have a bunch of dupes I can actually chase down.

Example: GitHub raised a warning about org.bitbucket.b_c:jose4j:0.7.0. I couldn't find it anywhere until it turned out it was a transitive dep of a Gradle plugin in the included build. Ended up running grep -R "jose4j" ~/.gradle/caches to get some idea where it was coming from.

@bigdaz
Copy link
Member

bigdaz commented Apr 22, 2024

Thanks for your comment. Were you aware of any of the additional documentation regarding "resolving dependency vulnerabilities"? (I'm wondering if there's a way to make these more prominent)

Although I don't think it's practical to make it easy to attribute dependencies directly in the GitHub UI, we could also generate an extra, detailed report with full dependency-path information. Or we could possibly add the full dependency-path information as metadata in the GitHub Dependency Graph file.

@madisp
Copy link

madisp commented Apr 22, 2024

Nope, I wasn't aware of those docs. I did manage to solve all of my issues by manually invoking the GitHub variant of the plugin locally though. I think the most ergonomic way for solving this would be perhaps exporting the generated .json file from GitHub Actions?

@bigdaz
Copy link
Member

bigdaz commented Apr 23, 2024

Thanks @madisp.
I've raised gradle/actions#195 to make this process easier in general.

@snuggie12
Copy link

We use renovate and was attempting to use the gradle dependency graph to auto-create PRs. The config passed to renovate come directly from this plugin. Therefore it is telling renovate to look in settings.gradle.kts for a specific dependency in order to substitute the string with an acceptable version.

I'm not a java developer, but best I can tell you can't declare dependencies inside of settings.gradle.kts short of maybe a catalog.

Would it be possible to make this file configurable? We don't have any subprojects so setting it to build.gradle.kts would give us an avenue to automate vuln fixing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants