1 # Adaptation of the MIT-licensed work on `sbt2nix` done by Charles O'Farrell
3 { lib, fetchurl, stdenv }:
6 "https://repo1.maven.org/maven2"
7 "https://oss.sonatype.org/content/repositories/releases"
8 "https://oss.sonatype.org/content/repositories/public"
9 "https://repo.typesafe.com/typesafe/releases"
14 { # Example: "org.apache.httpcomponents"
16 , # Example: "httpclient"
22 , # List of maven repositories from where to fetch the artifact.
23 # Example: [ http://oss.sonatype.org/content/repositories/public ].
25 # The `url` and `urls` parameters, if specified should point to the JAR
26 # file and will take precedence over the `repos` parameter. Only one of `url`
27 # and `urls` can be specified, not both.
30 , # The rest of the arguments are just forwarded to `fetchurl`.
34 # only one of url and urls can be specified at a time.
35 assert (url == "") || (urls == []);
36 # if repos is empty, then url or urls must be specified.
37 assert (repos != []) || (url != "") || (urls != []);
40 pname = (lib.replaceStrings [ "." ] [ "_" ] groupId) + "_" + (lib.replaceStrings [ "." ] [ "_" ] artifactId);
41 suffix = lib.optionalString (classifier != null) "-${classifier}";
42 filename = "${artifactId}-${version}${suffix}.jar";
44 lib.concatStringsSep "/" [
45 (lib.removeSuffix "/" repoUrl)
46 (lib.replaceStrings ["."] ["/"] groupId)
52 if url != "" then [url]
53 else if urls != [] then urls
54 else map mkJarUrl repos;
57 builtins.removeAttrs args [ "groupId" "artifactId" "version" "classifier" "repos" "url" ]
58 // { urls = urls_; name = "${pname}-${version}.jar"; }
62 inherit pname version;
64 # By moving the jar to $out/share/java we make it discoverable by java
65 # packages packages that mention this derivation in their buildInputs.
67 mkdir -p $out/share/java
68 ln -s ${jar} $out/share/java/${filename}
70 # We also add a `jar` attribute that can be used to easily obtain the path
71 # to the downloaded jar file.