@@ -0,0 +1,58 @@
1+{ stdenv, maven, runCommand, writeText, fetchurl, lib }:
2+/* Takes an info file generated by mvn2nix
3+ * (https://github.com/shlevy/mvn2nix-maven-plugin) and builds the maven
4+ * project with it.
5+ *
6+ * repo: A local maven repository with the project's dependencies.
7+ *
8+ * settings: A settings.xml to pass to maven to use the repo.
9+ *
10+ * build: A simple build derivation that uses mvn compile and package to build
11+ * the project.
12+ */
13+infoFile: let
14+ info = builtins.fromJSON (builtins.readFile infoFile);
15+
16+ repo = runCommand "maven-repository" {} ''
17+ ${lib.concatStrings (map (dep: let
18+ inherit (dep) url sha1 groupId artifactId version;
19+
20+ fetch = fetchurl { inherit url sha1; };
21+ in ''
22+ dir=$out/$(echo ${groupId} | sed 's|\.|/|g')/${artifactId}/${version}
23+ mkdir -p $dir
24+ ln -sv ${fetch} $dir/${fetch.name}
25+ '') info.dependencies)}
26+ '';
27+
28+ settings = writeText "settings.xml" ''
29+ <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
30+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
31+ xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
32+ http://maven.apache.org/xsd/settings-1.0.0.xsd">
33+ <localRepository>${repo}</localRepository>
34+ </settings>
35+ '';
36+
37+ src = dirOf infoFile;
38+in {
39+ inherit repo settings;
40+
41+ build = stdenv.mkDerivation {
42+ name = "${info.project.artifactId}-${info.project.version}.jar";
43+
44+ src = builtins.filterSource (path: type:
45+ (toString path) != (toString (src + "/target")) &&
46+ (toString path) != (toString (src + "/.git"))
47+ ) src;
48+
49+ buildInputs = [ maven ];
50+
51+ buildPhase = "mvn --offline --settings ${settings} compile";
52+
53+ installPhase = ''
54+ mvn --offline --settings ${settings} package
55+ mv target/*.jar $out
56+ '';
57+ };
58+}