diff options
author | William A. Kennington III <william@wkennington.com> | 2015-06-22 10:57:36 -0700 |
---|---|---|
committer | William A. Kennington III <william@wkennington.com> | 2015-06-22 10:57:36 -0700 |
commit | 282d03befa69b7b60a08a40200ad8218f3eadfa7 (patch) | |
tree | 59885694c8827979da3d9b29eec74205cd49e8a4 /pkgs/build-support | |
parent | ad779acd3be0a29bcda55f760eee6de35cfedef5 (diff) | |
parent | 22172b8e43dfac3486d108a085b5911d7e2d8c5a (diff) | |
download | nixlib-282d03befa69b7b60a08a40200ad8218f3eadfa7.tar nixlib-282d03befa69b7b60a08a40200ad8218f3eadfa7.tar.gz nixlib-282d03befa69b7b60a08a40200ad8218f3eadfa7.tar.bz2 nixlib-282d03befa69b7b60a08a40200ad8218f3eadfa7.tar.lz nixlib-282d03befa69b7b60a08a40200ad8218f3eadfa7.tar.xz nixlib-282d03befa69b7b60a08a40200ad8218f3eadfa7.tar.zst nixlib-282d03befa69b7b60a08a40200ad8218f3eadfa7.zip |
Merge branch 'master.upstream' into staging.upstream
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/build-maven.nix | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/pkgs/build-support/build-maven.nix b/pkgs/build-support/build-maven.nix new file mode 100644 index 000000000000..bde95080e745 --- /dev/null +++ b/pkgs/build-support/build-maven.nix @@ -0,0 +1,58 @@ +{ stdenv, maven, runCommand, writeText, fetchurl, lib }: +/* Takes an info file generated by mvn2nix + * (https://github.com/shlevy/mvn2nix-maven-plugin) and builds the maven + * 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 + info = builtins.fromJSON (builtins.readFile infoFile); + + repo = runCommand "maven-repository" {} '' + ${lib.concatStrings (map (dep: let + inherit (dep) url sha1 groupId artifactId version; + + fetch = fetchurl { inherit url sha1; }; + in '' + dir=$out/$(echo ${groupId} | sed 's|\.|/|g')/${artifactId}/${version} + mkdir -p $dir + ln -sv ${fetch} $dir/${fetch.name} + '') info.dependencies)} + ''; + + 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 { + inherit repo settings; + + 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 + ''; + }; +} |