summary refs log tree commit diff
path: root/pkgs/development/java-modules/build-maven-package.nix
blob: 182740c552d8d281f85e4e253ad5ad05da7bfc50 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{ stdenv, maven, lib }:
{ mavenDeps, src, name, meta, m2Path, ... }:

with builtins;
with lib;

stdenv.mkDerivation rec {
  inherit mavenDeps src name meta m2Path;

  flatDeps = flatten mavenDeps;

  propagatedBuildInput = [ maven ] ++ flatDeps;

  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 -rs ${foldl' (x: y: x + " " + y) "" (map (x: x + "/m2/*") flatDeps)} $out/m2'';

  buildPhase = ''
    mkdir -p $out/m2/${m2Path}
    ${optionalString (length flatDeps > 0) find}
    ${optionalString (length flatDeps > 0) copy}
    echo "<settings><mirrors>\
        <mirror><id>tmpm2</id><url>file://$out/m2</url><mirrorOf>*</mirrorOf></mirror></mirrors>\
        <localRepository>$out/m2</localRepository></settings>" >> $out/m2/settings.xml
    ${maven}/bin/mvn clean install -Dmaven.test.skip=true -gs $out/m2/settings.xml
  '';
}