2015-07-08 11:24:55 +01:00
|
|
|
{ stdenv, maven, runCommand, writeText, fetchurl, lib, requireFile }:
|
2015-06-22 03:24:03 +01:00
|
|
|
/* Takes an info file generated by mvn2nix
|
2015-07-01 13:11:05 +01:00
|
|
|
* (https://github.com/NixOS/mvn2nix-maven-plugin) and builds the maven
|
2015-06-22 03:24:03 +01:00
|
|
|
* project with it.
|
|
|
|
*
|
|
|
|
* repo: A local maven repository with the project's dependencies.
|
|
|
|
*
|
|
|
|
* settings: A settings.xml to pass to maven to use the repo.
|
|
|
|
*
|
|
|
|
* build: A simple build derivation that uses mvn compile and package to build
|
|
|
|
* the project.
|
|
|
|
*/
|
|
|
|
infoFile: let
|
2016-02-29 13:49:29 +00:00
|
|
|
info = lib.importJSON infoFile;
|
2015-06-22 03:24:03 +01:00
|
|
|
|
2015-06-29 18:41:24 +01:00
|
|
|
script = writeText "build-maven-repository.sh" ''
|
2015-06-22 03:24:03 +01:00
|
|
|
${lib.concatStrings (map (dep: let
|
2018-11-29 17:18:23 +00:00
|
|
|
inherit (dep) sha1 groupId artifactId version metadata repository-id;
|
2015-07-20 14:19:12 +01:00
|
|
|
|
|
|
|
versionDir = dep.unresolved-version or version;
|
2018-07-25 14:55:16 +01:00
|
|
|
authenticated = dep.authenticated or false;
|
2018-11-29 17:18:23 +00:00
|
|
|
url = dep.url or "";
|
2015-06-22 03:24:03 +01:00
|
|
|
|
2018-11-29 17:18:23 +00:00
|
|
|
fetch = if (url != "") then ((if authenticated then requireFile else fetchurl) {
|
2015-07-08 11:24:55 +01:00
|
|
|
inherit url sha1;
|
2018-11-29 17:18:23 +00:00
|
|
|
}) else "";
|
2015-07-20 14:19:12 +01:00
|
|
|
|
|
|
|
fetchMetadata = (if authenticated then requireFile else fetchurl) {
|
|
|
|
inherit (metadata) url sha1;
|
|
|
|
};
|
2015-06-22 03:24:03 +01:00
|
|
|
in ''
|
2015-07-20 14:19:12 +01:00
|
|
|
dir=$out/$(echo ${groupId} | sed 's|\.|/|g')/${artifactId}/${versionDir}
|
2015-06-22 03:24:03 +01:00
|
|
|
mkdir -p $dir
|
2018-11-29 17:18:23 +00:00
|
|
|
|
|
|
|
${lib.optionalString (fetch != "") ''
|
|
|
|
ln -sv ${fetch} $dir/${fetch.name}
|
|
|
|
''}
|
2015-07-20 14:19:12 +01:00
|
|
|
${lib.optionalString (dep ? metadata) ''
|
|
|
|
ln -svf ${fetchMetadata} $dir/maven-metadata-${repository-id}.xml
|
2018-11-29 17:18:23 +00:00
|
|
|
${lib.optionalString (fetch != "") ''
|
|
|
|
ln -sv ${fetch} $dir/$(echo ${fetch.name} | sed 's|${version}|${dep.unresolved-version}|')
|
|
|
|
''}
|
2015-07-20 14:19:12 +01:00
|
|
|
''}
|
2015-06-22 03:24:03 +01:00
|
|
|
'') info.dependencies)}
|
|
|
|
'';
|
|
|
|
|
2015-06-29 18:41:24 +01:00
|
|
|
repo = runCommand "maven-repository" {} ''
|
|
|
|
bash ${script}
|
|
|
|
'';
|
|
|
|
|
2015-06-22 03:24:03 +01:00
|
|
|
settings = writeText "settings.xml" ''
|
|
|
|
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
|
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
|
|
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
|
|
|
|
http://maven.apache.org/xsd/settings-1.0.0.xsd">
|
|
|
|
<localRepository>${repo}</localRepository>
|
|
|
|
</settings>
|
|
|
|
'';
|
|
|
|
|
|
|
|
src = dirOf infoFile;
|
|
|
|
in {
|
2015-07-14 10:58:54 +01:00
|
|
|
inherit repo settings info;
|
2015-06-22 03:24:03 +01:00
|
|
|
|
|
|
|
build = stdenv.mkDerivation {
|
|
|
|
name = "${info.project.artifactId}-${info.project.version}.jar";
|
|
|
|
|
|
|
|
src = builtins.filterSource (path: type:
|
|
|
|
(toString path) != (toString (src + "/target")) &&
|
|
|
|
(toString path) != (toString (src + "/.git"))
|
|
|
|
) src;
|
|
|
|
|
|
|
|
buildInputs = [ maven ];
|
|
|
|
|
|
|
|
buildPhase = "mvn --offline --settings ${settings} compile";
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mvn --offline --settings ${settings} package
|
|
|
|
mv target/*.jar $out
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|