Home Explore Blog CI



nixpkgs

2nd chunk of `doc/languages-frameworks/gradle.section.md`
e9a5baf65a62d9785303d922b945241b266ee87a830efb3a00000001000008f6
    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 Update Script and Environment Configuration
Summary
This section details the functionality of the Gradle update script, which builds the derivation source, enters a sandboxed nix-shell, sets the `IN_GRADLE_UPDATE_DEPS` environment variable, and executes derivation phases and hooks. It also describes how the script stores file hashes in the lockfile. Additionally, it outlines the arguments accepted by `fetchDeps`, including `attrPath`, `pname`, `pkg`, `bwrapFlags`, and `data`, and mentions environment variables that the Gradle setup hook utilizes, such as `mitmCache` and `gradleFlags`.