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.
This commit is contained in:
Thibault Gagnaux 2023-09-14 13:22:59 +02:00
parent 295a5e1e2b
commit 9a7693b704
No known key found for this signature in database
GPG Key ID: 44BD0764ACAE8E25

View File

@ -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
'';