1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-25 03:17:13 +00:00
nixpkgs/pkgs/development/java-modules/build-maven-package.nix

35 lines
1.3 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
mavenMinimal = import ./maven-minimal.nix { inherit pkgs stdenv; };
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;
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 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 17:08:51 +01: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
'';
}