|
1 | | -# GitHub Dependency Extractor |
| 1 | +# GitHub Dependency Graph Gradle Plugin |
2 | 2 |
|
3 | | -A Gradle plugin for extracting dependencies from a Gradle build to feed the GitHub Dependency API. |
| 3 | +A Gradle plugin for generating a GitHub dependency graph for a Gradle build, which can be uploaded to the [GitHub Dependency Submission API](https://docs.github.com/en/rest/dependency-graph/dependency-submission). |
4 | 4 |
|
5 | | -This project is currently just a proof of concept, but ideally, this plugin would be automatically applied to any Gradle |
6 | | -project using the GitHub Action [gradle-build-action](https://github.com/marketplace/actions/gradle-build-action). |
| 5 | +## Usage |
| 6 | +This plugin is designed to be used in a GitHub Actions workflow, with support coming in a future release of the [Gradle Build Action](https://github.com/gradle/gradle-build-action). |
7 | 7 |
|
8 | | -This plugin leverages the same internal API's used by the Gradle Build Scan Plugin. |
| 8 | +For other uses, the [core plugin](https://plugins.gradle.org/plugin/org.gradle.github-dependency-graph-gradle-plugin) (`org.gradle.github.GitHubDependencyGraphPlugin`) |
| 9 | +should be applied to the `Gradle` instance via a Gradle init script as follows: |
9 | 10 |
|
10 | | -This plugin is intended to implement the proposed API for the GitHub Build-Time Dependency Graph API found |
11 | | -[here](https://docs.google.com/document/d/1TjxJJwgPavw-TFzK3110iH-CWstgdcVdb2JYiRy2GVs/edit?usp=sharing) |
12 | | -and this |
13 | | -[JSON Schema](https://gist.github.com/reiddraper/7b47d553382fd3867cc1d0b5474bd6c7). |
| 11 | +``` |
| 12 | +import org.gradle.github.GitHubDependencyGraphPlugin |
| 13 | +initscript { |
| 14 | + repositories { |
| 15 | + maven { |
| 16 | + url = uri("https://plugins.gradle.org/m2/") |
| 17 | + } |
| 18 | + } |
| 19 | + dependencies { |
| 20 | + classpath("org.gradle:github-dependency-graph-gradle-plugin:+") |
| 21 | + } |
| 22 | +} |
| 23 | +apply plugin: GitHubDependencyGraphPlugin |
| 24 | +``` |
| 25 | + |
| 26 | +This causes 2 separate plugins to be applied, that can be used independently: |
| 27 | +- `GitHubDependencyExtractorPlugin` collects all dependencies that are resolved during a build execution and writes these to a file. The output file can be found at `<root>/build/reports/github-depenency-graph-gradle-plugin/github-dependency-snapshot.json`. |
| 28 | +- `ForceDependencyResolutionPlugin` creates a `GitHubDependencyGraphPlugin_generateDependencyGraph` task that will attempt to resolve all dependencies for a Gradle build, by simply invoking `dependencies` on all projects. |
14 | 29 |
|
15 | 30 | ## Building/Testing |
16 | 31 |
|
17 | | -To test this plugin, run the following task: |
| 32 | +To build and test this plugin, run the following task: |
18 | 33 | ```shell |
19 | | -./gradlew test |
| 34 | +./gradlew check |
20 | 35 | ``` |
21 | 36 |
|
22 | | -Self testing this plugin is also possible. |
23 | | -In order to do this, you'll need a |
24 | | -[GitHub API token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) |
25 | | -set to the environment variable `GITHUB_TOKEN`. |
26 | | - |
27 | | -To run the self-test, run the following: |
| 37 | +To self-test this plugin and generate a dependency graph for this repository, run: |
28 | 38 | ```shell |
29 | | -./gradlew build |
30 | 39 | ./plugin-self-test-local |
31 | 40 | ``` |
| 41 | + |
| 42 | +The generated dependency graph will be submitted to GitHub only if you supply a |
| 43 | +[GitHub API token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) |
| 44 | +via the environment variable `GITHUB_TOKEN`. |
0 commit comments