diff options
author | Alyssa Ross <hi@alyssa.is> | 2019-01-07 02:18:36 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2019-01-07 02:18:47 +0000 |
commit | 36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2 (patch) | |
tree | b3faaf573407b32aa645237a4d16b82778a39a92 /nixpkgs/pkgs/build-support/build-maven.nix | |
parent | 4e31070265257dc67d120c27e0f75c2344fdfa9a (diff) | |
parent | abf060725d7614bd3b9f96764262dfbc2f9c2199 (diff) | |
download | nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.gz nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.bz2 nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.lz nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.xz nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.zst nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.zip |
Add 'nixpkgs/' from commit 'abf060725d7614bd3b9f96764262dfbc2f9c2199'
git-subtree-dir: nixpkgs git-subtree-mainline: 4e31070265257dc67d120c27e0f75c2344fdfa9a git-subtree-split: abf060725d7614bd3b9f96764262dfbc2f9c2199
Diffstat (limited to 'nixpkgs/pkgs/build-support/build-maven.nix')
-rw-r--r-- | nixpkgs/pkgs/build-support/build-maven.nix | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/build-support/build-maven.nix b/nixpkgs/pkgs/build-support/build-maven.nix new file mode 100644 index 000000000000..f47e3ebc61c2 --- /dev/null +++ b/nixpkgs/pkgs/build-support/build-maven.nix @@ -0,0 +1,81 @@ +{ stdenv, maven, runCommand, writeText, fetchurl, lib, requireFile }: +/* Takes an info file generated by mvn2nix + * (https://github.com/NixOS/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 = lib.importJSON infoFile; + + script = writeText "build-maven-repository.sh" '' + ${lib.concatStrings (map (dep: let + inherit (dep) sha1 groupId artifactId version metadata repository-id; + + versionDir = dep.unresolved-version or version; + authenticated = dep.authenticated or false; + url = dep.url or ""; + + fetch = if (url != "") then ((if authenticated then requireFile else fetchurl) { + inherit url sha1; + }) else ""; + + fetchMetadata = (if authenticated then requireFile else fetchurl) { + inherit (metadata) url sha1; + }; + in '' + dir=$out/$(echo ${groupId} | sed 's|\.|/|g')/${artifactId}/${versionDir} + mkdir -p $dir + + ${lib.optionalString (fetch != "") '' + ln -sv ${fetch} $dir/${fetch.name} + ''} + ${lib.optionalString (dep ? metadata) '' + ln -svf ${fetchMetadata} $dir/maven-metadata-${repository-id}.xml + ${lib.optionalString (fetch != "") '' + ln -sv ${fetch} $dir/$(echo ${fetch.name} | sed 's|${version}|${dep.unresolved-version}|') + ''} + ''} + '') info.dependencies)} + ''; + + repo = runCommand "maven-repository" {} '' + bash ${script} + ''; + + 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 info; + + 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 + ''; + }; +} |