nixpkgs/pkgs/development/java-modules/build-maven-package.nix

35 lines
1.4 KiB
Nix
Raw Normal View History

2016-10-31 17:10:26 +00:00
{ stdenv, maven, pkgs }:
2016-11-15 19:18:19 +00:00
{ mavenDeps, src, name, meta, m2Path, skipTests ? true, quiet ? true, ... }:
2016-10-30 15:41:20 +00:00
with builtins;
2016-10-31 17:10:26 +00:00
with stdenv.lib;
2016-10-30 15:41:20 +00:00
2016-10-31 14:23:22 +00:00
let
2016-10-31 17:10:26 +00:00
mavenMinimal = import ./maven-minimal.nix { inherit pkgs stdenv maven; };
2016-10-31 14:23:22 +00:00
in stdenv.mkDerivation rec {
2016-10-30 15:41:20 +00:00
inherit mavenDeps src name meta m2Path;
2016-10-31 14:23:22 +00:00
flatDeps = unique (flatten (mavenDeps ++ mavenMinimal.mavenMinimal));
2016-10-30 15:41:20 +00:00
propagatedBuildInput = [ maven ] ++ flatDeps;
2016-11-15 19:18:19 +00:00
find = ''find ${foldl' (x: y: x + " " + y) "" (map (x: x + "/m2") flatDeps)} -type d -printf '%P\n' | xargs -I {} mkdir -p $out/m2/{}'';
copy = ''cp -rsfu ${foldl' (x: y: x + " " + y) "" (map (x: x + "/m2/*") flatDeps)} $out/m2'';
2016-10-30 15:41:20 +00:00
2016-10-31 17:10:26 +00:00
phases = [ "unpackPhase" "buildPhase" ];
2016-10-30 15:41:20 +00:00
buildPhase = ''
2016-10-31 17:10:26 +00:00
mkdir -p $out/target
2016-10-30 15:41:20 +00:00
mkdir -p $out/m2/${m2Path}
${optionalString (length flatDeps > 0) find}
${optionalString (length flatDeps > 0) copy}
2016-11-15 19:18:19 +00:00
if [ -f $out/m2/settings.xml ]; then rm $out/m2/settings.xml; fi
2016-10-30 15:41:20 +00:00
echo "<settings><mirrors>\
2016-11-15 19:18:19 +00:00
<mirror><id>tmpm2</id><url>file://$out/m2</url><mirrorOf>*</mirrorOf></mirror></mirrors>\
<localRepository>$out/m2/</localRepository></settings>" >> $out/m2/settings.xml
2017-04-11 16:08:51 +00:00
${maven}/bin/mvn ${optionalString (quiet) "-q"} clean package -Dmaven.test.skip=${boolToString skipTests} -Danimal.sniffer.skip=true -gs $out/m2/settings.xml
2016-11-15 19:18:19 +00:00
cp ./target/*.jar $out/m2/${m2Path}
2016-10-31 17:10:26 +00:00
cp -v ./target/*.jar $out/target/
2016-10-30 15:41:20 +00:00
'';
}