···4949After setting `maven.buildMavenPackage`, we then do standard Java `.jar` installation by saving the `.jar` to `$out/share/java` and then making a wrapper which allows executing that file; see [](#sec-language-java) for additional generic information about packaging Java applications.
5050:::
51515252+### Overriding Maven package attributes {#maven-overriding-package-attributes}
5353+5454+```
5555+overrideMavenAttrs :: (AttrSet -> Derivation) | ((AttrSet -> Attrset) -> Derivation) -> Derivation
5656+```
5757+5858+The output of `buildMavenPackage` has an `overrideMavenAttrs` attribute, which is a function that takes either
5959+- any subset of the attributes that can be passed to `buildMavenPackage`
6060+6161+ or
6262+- a function that takes the argument passed to the previous invocation of `buildMavenPackage` (conventionally called `old`) and returns an attribute set that can be passed to `buildMavenPackage`
6363+6464+and returns a derivation that builds a Maven package based on the old and new arguments merged.
6565+6666+This is similar to [](#sec-pkg-overrideAttrs), but notably does not allow accessing the final value of the argument to `buildMavenPackage`.
6767+6868+:::{.example}
6969+### `overrideMavenAttrs` Example
7070+7171+Use `overrideMavenAttrs` to build `jd-cli` version 1.2.0 and disable some flaky test:
7272+7373+```nix
7474+jd-cli.overrideMavenAttrs (old: rec {
7575+ version = "1.2.0";
7676+ src = fetchFromGitHub {
7777+ owner = old.src.owner;
7878+ repo = old.src.repo;
7979+ rev = "${old.pname}-${version}";
8080+ # old source hash of 1.2.0 version
8181+ hash = "sha256-US7j6tQ6mh1libeHnQdFxPGoxHzbZHqehWSgCYynKx8=";
8282+ };
8383+8484+ # tests can be disabled by prefixing it with `!`
8585+ # see Maven documentation for more details:
8686+ # https://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html#Multiple_Formats_in_One
8787+ mvnParameters = lib.escapeShellArgs [
8888+ "-Dsurefire.failIfNoSpecifiedTests=false"
8989+ "-Dtest=!JavaDecompilerTest#basicTest,!JavaDecompilerTest#patternMatchingTest"
9090+ ];
9191+9292+ # old mvnHash of 1.2.0 maven dependencies
9393+ mvnHash = "sha256-N9XC1pg6Y4sUiBWIQUf16QSXCuiAPpXEHGlgApviF4I=";
9494+});
9595+```
9696+:::
9797+9898+### Offline build {#maven-offline-build}
9999+100100+By default, `buildMavenPackage` does the following:
101101+102102+1. Run `mvn package -Dmaven.repo.local=$out/.m2 ${mvnParameters}` in the
103103+ `fetchedMavenDeps` [fixed-output derivation](https://nixos.org/manual/nix/stable/glossary.html#gloss-fixed-output-derivation).
104104+2. Run `mvn package -o -nsu "-Dmaven.repo.local=$mvnDeps/.m2"
105105+ ${mvnParameters}` again in the main derivation.
106106+107107+As a result, tests are run twice.
108108+This also means that a failing test will trigger a new attempt to realise the fixed-output derivation, which in turn downloads all dependencies again.
109109+For bigger Maven projects, this might lead to a long feedback cycle.
110110+111111+Use `buildOffline = true` to change the behaviour of `buildMavenPackage to the following:
112112+1. Run `mvn de.qaware.maven:go-offline-maven-plugin:1.2.8:resolve-dependencies
113113+ -Dmaven.repo.local=$out/.m2 ${mvnDepsParameters}` in the fixed-output derivation.
114114+2. Run `mvn package -o -nsu "-Dmaven.repo.local=$mvnDeps/.m2"
115115+ ${mvnParameters}` in the main derivation.
116116+117117+As a result, all dependencies are downloaded in step 1 and the tests are executed in step 2.
118118+A failing test only triggers a rebuild of step 2 as it can reuse the dependencies of step 1 because they have not changed.
119119+120120+::: {.warning}
121121+Test dependencies are not downloaded in step 1 and are therefore missing in
122122+step 2 which will most probably fail the build. The `go-offline` plugin cannot
123123+handle these so-called [dynamic dependencies](https://github.com/qaware/go-offline-maven-plugin?tab=readme-ov-file#dynamic-dependencies).
124124+In that case you must add these dynamic dependencies manually with:
125125+```nix
126126+maven.buildMavenPackage rec {
127127+ manualMvnArtifacts = [
128128+ # add dynamic test dependencies here
129129+ "org.apache.maven.surefire:surefire-junit-platform:3.1.2"
130130+ "org.junit.platform:junit-platform-launcher:1.10.0"
131131+ ];
132132+};
133133+```
134134+:::
135135+52136### Stable Maven plugins {#stable-maven-plugins}
5313754138Maven defines default versions for its core plugins, e.g. `maven-compiler-plugin`. If your project does not override these versions, an upgrade of Maven will change the version of the used plugins, and therefore the derivation and hash.
···7171 if cargoVendorDir != null then null
7272 else if cargoDeps != null then cargoDeps
7373 else if cargoLock != null then importCargoLock cargoLock
7474- else if useFetchCargoVendor then (fetchCargoVendor {
7474+ else if useFetchCargoVendor then fetchCargoVendor ({
7575 inherit src srcs sourceRoot preUnpack unpackPhase postUnpack;
7676 name = cargoDepsName;
7777 patches = cargoPatches;