From 9a7693b7044146879c9cd7c9aab6154d73a8e73d Mon Sep 17 00:00:00 2001 From: Thibault Gagnaux Date: Thu, 14 Sep 2023 13:22:59 +0200 Subject: [PATCH] buildMavenPackage: refactor to run test in drv only Uses the dependency:go-offline goal in the fixed output derivation to download all dependencies. As a result, the derivation can be built and tested offline in the main derivation. The advantage of this approach is that you don't need to redownload all dependencies if there are test failures. --- .../build-managers/apache-maven/build-package.nix | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkgs/development/tools/build-managers/apache-maven/build-package.nix b/pkgs/development/tools/build-managers/apache-maven/build-package.nix index 2026d6829371..45abbb5db1d9 100644 --- a/pkgs/development/tools/build-managers/apache-maven/build-package.nix +++ b/pkgs/development/tools/build-managers/apache-maven/build-package.nix @@ -10,6 +10,8 @@ , version , mvnHash ? "" , mvnFetchExtraArgs ? { } +, mvnDepsParameters ? "" +, manualMvnArtifactIds ? [ ] , mvnParameters ? "" , ... } @args: @@ -29,7 +31,13 @@ let buildPhase = '' runHook preBuild - mvn package -Dmaven.repo.local=$out/.m2 ${mvnParameters} + mvn dependency:go-offline -Dmaven.repo.local=$out/.m2 ${mvnDepsParameters} + + for artifactId in ${builtins.toString manualMvnArtifactIds} + do + echo "downloading manual $artifactId" + mvn dependency:get -Dartifact="$artifactId" -Dmaven.repo.local=$out/.m2 + done runHook postBuild ''; @@ -65,7 +73,7 @@ stdenv.mkDerivation (builtins.removeAttrs args [ "mvnFetchExtraArgs" ] // { runHook preBuild mvnDeps=$(cp -dpR ${fetchedMavenDeps}/.m2 ./ && chmod +w -R .m2 && pwd) - mvn package --offline "-Dmaven.repo.local=$mvnDeps/.m2" ${mvnParameters} + mvn package -o -nsu "-Dmaven.repo.local=$mvnDeps/.m2" ${mvnParameters} runHook postBuild '';