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

35 lines
1.3 KiB
Nix
Raw Normal View History

2016-10-31 18:10:26 +01:00
{ stdenv, maven, pkgs }:
2016-11-15 20:18:19 +01:00
{ mavenDeps, src, name, meta, m2Path, skipTests ? true, quiet ? true, ... }:
2016-10-30 16:41:20 +01:00
with builtins;
2016-10-31 18:10:26 +01:00
with stdenv.lib;
2016-10-30 16:41:20 +01:00
2016-10-31 15:23:22 +01:00
let
mavenMinimal = import ./maven-minimal.nix { inherit pkgs stdenv; };
2016-10-31 15:23:22 +01:00
in stdenv.mkDerivation rec {
2016-10-30 16:41:20 +01:00
inherit mavenDeps src name meta m2Path;
2016-10-31 15:23:22 +01:00
flatDeps = unique (flatten (mavenDeps ++ mavenMinimal.mavenMinimal));
2016-10-30 16:41:20 +01:00
propagatedBuildInput = [ maven ] ++ flatDeps;
find = ''find ${concatStringsSep " " (map (x: x + "/m2") flatDeps)} -type d -printf '%P\n' | xargs -I {} mkdir -p $out/m2/{}'';
copy = ''cp -rsfu ${concatStringsSep " " (map (x: x + "/m2/*") flatDeps)} $out/m2'';
2016-10-30 16:41:20 +01:00
2016-10-31 18:10:26 +01:00
phases = [ "unpackPhase" "buildPhase" ];
2016-10-30 16:41:20 +01:00
buildPhase = ''
2016-10-31 18:10:26 +01:00
mkdir -p $out/target
2016-10-30 16:41:20 +01:00
mkdir -p $out/m2/${m2Path}
${optionalString (length flatDeps > 0) find}
${optionalString (length flatDeps > 0) copy}
2016-11-15 20:18:19 +01:00
if [ -f $out/m2/settings.xml ]; then rm $out/m2/settings.xml; fi
2016-10-30 16:41:20 +01:00
echo "<settings><mirrors>\
2016-11-15 20:18:19 +01: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 18:08:51 +02: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 20:18:19 +01:00
cp ./target/*.jar $out/m2/${m2Path}
2016-10-31 18:10:26 +01:00
cp -v ./target/*.jar $out/target/
2016-10-30 16:41:20 +01:00
'';
}