Home Explore Blog Models CI



nixpkgs

2nd chunk of `doc/languages-frameworks/gradle.section.md`
687d0521c2a7b900c9a0fbecddd37c4ee1ee91344169b33800000001000008f6
    pkg = finalAttrs.finalPackage;
    data = ./deps.json;
  };
})
```
The limitation of this method is that you cannot override the `pkg` derivations's arguments.

In the former case, the update script will stay the same even if the derivation is called with different arguments. In the latter case, the update script will change depending on the derivation arguments. It's up to you to decide which one would work best for your derivation.

## Update Script {#gradle-update-script}

The update script does the following:

- Build the derivation's source via `pkgs.srcOnly`
- Enter a `nix-shell` for the derivation in a `bwrap` sandbox (the
  sandbox is only used on Linux)
- Set the `IN_GRADLE_UPDATE_DEPS` environment variable to `1`
- Run the derivation's `unpackPhase`, `patchPhase`, `configurePhase`
- Run the derivation's `gradleUpdateScript` (the Gradle setup hook sets
  a default value for it, which runs `preBuild`, `preGradleUpdate`
  hooks, fetches the dependencies using `gradleUpdateTask`, and finally
  runs the `postGradleUpdate` hook)
- Finally, store all of the fetched files' hashes in the lockfile. They
  may be `.jar`/`.pom` files from Maven repositories, or they may be
  files otherwise used for building the package.

`fetchDeps` takes the following arguments:

- `attrPath` - the path to the package in nixpkgs (for example,
  `"javaPackages.openjfx22"`). Used for update script metadata.
- `pname` - an alias for `attrPath` for convenience. This is what you
  will generally use instead of `pkg` or `attrPath`.
- `pkg` - the package to be used for fetching the dependencies. Defaults
  to `getAttrFromPath (splitString "." attrPath) pkgs`.
- `bwrapFlags` - allows you to override bwrap flags (only relevant for
  downstream, non-nixpkgs projects)
- `data` - path to the dependencies lockfile (can be relative to the
  package, can be absolute). In nixpkgs, it's discouraged to have the
  lockfiles be named anything other `deps.json`, consider creating
  subdirectories if your package requires multiple `deps.json` files.

## Environment {#gradle-environment}

The Gradle setup hook accepts the following environment variables:

- `mitmCache` - the MITM proxy cache imported using `gradle.fetchDeps`
- `gradleFlags` - command-line flags to be used for every Gradle

Title: Gradle Dependency Update Script and Configuration
Summary
This section concludes the discussion on using `finalAttrs.finalPackage` with `gradle.fetchDeps`, noting its impact on the update script's variability and the inability to override `pkg` arguments. It then elaborates on the `gradleUpdateScript`'s detailed process: building the source, sandboxing with `bwrap` (Linux-only), setting `IN_GRADLE_UPDATE_DEPS`, executing various build phases and Gradle-specific hooks, and finally storing the hashes of fetched dependencies (e.g., JARs, POMs) in a lockfile. The text also lists the arguments accepted by `fetchDeps`, including `attrPath`, `pname`, `pkg`, `bwrapFlags`, and `data` (for the `deps.json` lockfile), and introduces `mitmCache` and `gradleFlags` as environment variables for the Gradle setup hook.