gradle/github-dependency-graph-gradle-plugin

Plugin application is confusing

Closed this issue · 4 comments

I have to apply the GitHubDependencySubmissionPlugin to "gradle" instead of the project, as I would normally expect.

I would expect:

apply plugin: GitHubDependencySubmissionPlugin

But instead I have to do:

project.gradle.apply(plugin: GitHubDependencySubmissionPlugin)

I don't understand why this is built as Plugin<Gradle> instead of Plugin<Project>.

The plugin is intenteded to be applied from within a Gradle init script.

https://docs.gradle.org/current/userguide/init_scripts.html

Init scripts are applied to the Gradle object.

We do this because we want to hook Gradle's dependency resolution engine as early as possible in the builds lifecycle so we don't miss dependency resolution events that occur either from other init scripts, settings scripts, or buildSrc builds.

If you apply this plugin from within an init script, you should be able to just use what you expected to work originally.

apply plugin: GitHubDependencySubmissionPlugin

Ah, I think I understand. So the idea is that this registers a service that listens for any specific resolution events, and accumulates a list of dependencies that were resolved. When the build is finished, the dependencies are written out to the JSON file.

That explains why there's no specific task to run to generate the JSON -- it's all in the background.

The good news is that for my use-case, we already have an internal Gradle distribution with an init script, so we can probably integrate this into our internal Gradle distribution without too much difficulty. We also usually use an internal build wrapper that only gets invoked with CI. That wrapper can be trained to look for the JSON files and send them to GitHub -- it already does similar things for Jacoco and JUnit results.

Ah, I think I understand. So the idea is that this registers a service that listens for any specific resolution events, and accumulates a list of dependencies that were resolved. When the build is finished, the dependencies are written out to the JSON file.

Correct, this is similar to how the Gradle Enterprise plugin works.

That explains why there's no specific task to run to generate the JSON -- it's all in the background.

Yep! Also correct!

Yeah, we don't use the Gradle Enterprise plugin. Thanks! I'll go ahead and close this and refer to #33 .