about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/tools/build-managers/gradle
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/tools/build-managers/gradle')
-rw-r--r--nixpkgs/pkgs/development/tools/build-managers/gradle/default.nix150
-rwxr-xr-xnixpkgs/pkgs/development/tools/build-managers/gradle/update.sh67
2 files changed, 217 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/tools/build-managers/gradle/default.nix b/nixpkgs/pkgs/development/tools/build-managers/gradle/default.nix
new file mode 100644
index 000000000000..b0b5e10729bf
--- /dev/null
+++ b/nixpkgs/pkgs/development/tools/build-managers/gradle/default.nix
@@ -0,0 +1,150 @@
+{ jdk8, jdk11, jdk17 }:
+
+rec {
+  gen =
+
+    { version, nativeVersion, sha256,
+
+      # The default JDK/JRE that will be used for derived Gradle packages.
+      # A current LTS version of a JDK is a good choice.
+      defaultJava ? jdk8,
+
+      # The platforms supported by this Gradle package.
+      # Gradle Native-Platform ships some binaries that
+      # are compatible only with specific platforms.
+      # As of 2022-04 this affects platform compatibility
+      # of multiple Gradle releases, so this is used as default.
+      # See https://github.com/gradle/native-platform#supported-platforms
+      platforms ? [
+        "aarch64-darwin"
+        "aarch64-linux"
+        "i686-windows"
+        "x86_64-cygwin"
+        "x86_64-darwin"
+        "x86_64-linux"
+        "x86_64-windows"
+      ]
+    }:
+
+    { lib, stdenv, fetchurl, makeWrapper, unzip, ncurses5, ncurses6,
+
+      # The JDK/JRE used for running Gradle.
+      java ? defaultJava,
+
+      # Additional JDK/JREs to be registered as toolchains.
+      # See https://docs.gradle.org/current/userguide/toolchains.html
+      javaToolchains ? [ ]
+    }:
+
+    stdenv.mkDerivation rec {
+      pname = "gradle";
+      inherit version;
+
+      src = fetchurl {
+        inherit sha256;
+        url =
+          "https://services.gradle.org/distributions/gradle-${version}-bin.zip";
+      };
+
+      dontBuild = true;
+
+      nativeBuildInputs = [ makeWrapper unzip ];
+      buildInputs = [ java ];
+
+      installPhase = with builtins;
+        let
+          toolchain = rec {
+            prefix = x: "JAVA_TOOLCHAIN_NIX_${toString x}";
+            varDefs  = (lib.imap0 (i: x: "${prefix i} ${x}") javaToolchains);
+            varNames = lib.imap0 (i: x: prefix i) javaToolchains;
+            property = " -Porg.gradle.java.installations.fromEnv='${
+                 concatStringsSep "," varNames
+               }'";
+          };
+          varDefs = concatStringsSep "\n" (map (x: "  --set ${x} \\")
+            ([ "JAVA_HOME ${java}" ] ++ toolchain.varDefs));
+        in ''
+          mkdir -pv $out/lib/gradle/
+          cp -rv lib/ $out/lib/gradle/
+
+          gradle_launcher_jar=$(echo $out/lib/gradle/lib/gradle-launcher-*.jar)
+          test -f $gradle_launcher_jar
+          makeWrapper ${java}/bin/java $out/bin/gradle \
+            ${varDefs}
+            --add-flags "-classpath $gradle_launcher_jar org.gradle.launcher.GradleMain${toolchain.property}"
+        '';
+
+      dontFixup = !stdenv.isLinux;
+
+      fixupPhase = let arch = if stdenv.is64bit then "amd64" else "i386";
+      in ''
+        for variant in "" "-ncurses5" "-ncurses6"; do
+          mkdir "patching$variant"
+          pushd "patching$variant"
+          jar xf $out/lib/gradle/lib/native-platform-linux-${arch}$variant-${nativeVersion}.jar
+          patchelf \
+            --set-rpath "${stdenv.cc.cc.lib}/lib64:${lib.makeLibraryPath [ stdenv.cc.cc ncurses5 ncurses6 ]}" \
+            net/rubygrapefruit/platform/linux-${arch}$variant/libnative-platform*.so
+          jar cf native-platform-linux-${arch}$variant-${nativeVersion}.jar .
+          mv native-platform-linux-${arch}$variant-${nativeVersion}.jar $out/lib/gradle/lib/
+          popd
+        done
+
+        # The scanner doesn't pick up the runtime dependency in the jar.
+        # Manually add a reference where it will be found.
+        mkdir $out/nix-support
+        echo ${stdenv.cc.cc} > $out/nix-support/manual-runtime-dependencies
+        # Gradle will refuse to start without _both_ 5 and 6 versions of ncurses.
+        echo ${ncurses5} >> $out/nix-support/manual-runtime-dependencies
+        echo ${ncurses6} >> $out/nix-support/manual-runtime-dependencies
+      '';
+
+      meta = with lib; {
+        inherit platforms;
+        description = "Enterprise-grade build system";
+        longDescription = ''
+          Gradle is a build system which offers you ease, power and freedom.
+          You can choose the balance for yourself. It has powerful multi-project
+          build support. It has a layer on top of Ivy that provides a
+          build-by-convention integration for Ivy. It gives you always the choice
+          between the flexibility of Ant and the convenience of a
+          build-by-convention behavior.
+        '';
+        homepage = "https://www.gradle.org/";
+        changelog = "https://docs.gradle.org/${version}/release-notes.html";
+        downloadPage = "https://gradle.org/next-steps/?version=${version}";
+        sourceProvenance = with sourceTypes; [
+          binaryBytecode
+          binaryNativeCode
+        ];
+        license = licenses.asl20;
+        maintainers = with maintainers; [ lorenzleutgeb liff ];
+        mainProgram = "gradle";
+      };
+    };
+
+  # NOTE: Default JDKs that are hardcoded below must be LTS versions
+  # and respect the compatibility matrix at
+  # https://docs.gradle.org/current/userguide/compatibility.html
+
+  gradle_8 = gen {
+    version = "8.3";
+    nativeVersion = "0.22-milestone-24";
+    sha256 = "09cjyss4bcnig1wzhxpwyn4kznkawzaha7fy0jg5nqzw2ysma62r";
+    defaultJava = jdk17;
+  };
+
+  gradle_7 = gen {
+    version = "7.6.2";
+    nativeVersion = "0.22-milestone-24";
+    sha256 = "1b7riri2ysr1bvfskmmb8phfx8c2b719kqhf189fvrszw63na6x0";
+    defaultJava = jdk17;
+  };
+
+  gradle_6 = gen {
+    version = "6.9.4";
+    nativeVersion = "0.22-milestone-20";
+    sha256 = "16iqh4bn7ndch51h2lgkdqyyhnd91fdfjx55fa3z3scdacl0491y";
+    defaultJava = jdk11;
+  };
+}
diff --git a/nixpkgs/pkgs/development/tools/build-managers/gradle/update.sh b/nixpkgs/pkgs/development/tools/build-managers/gradle/update.sh
new file mode 100755
index 000000000000..0d6b78a66525
--- /dev/null
+++ b/nixpkgs/pkgs/development/tools/build-managers/gradle/update.sh
@@ -0,0 +1,67 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p nix-prefetch curl jq
+
+# Generates Gradle release specs from GitHub Releases.
+#
+# As of 2021-11, this script has very poor error handling,
+# it is expected to be run by maintainers as one-off job
+# only.
+#
+# NOTE: The earliest Gradle release that has a
+# corresponding entry as GitHub Release is 6.8-rc-1.
+
+for v in $(curl -s "https://api.github.com/repos/gradle/gradle/releases" | jq -r '.[].tag_name' | sort -n -r)
+do
+    # Tag names and download filenames are not the same,
+    # we modify the tag name slightly to translate it
+    # to the naming scheme of download filenames.
+    # This translation assumes a tag naming scheme.
+    # As of 2021-11 it works from 6.8-rc-1 to 7.3-rc-3.
+
+    # Remove first letter (assumed to be "v").
+    v=${v:1}
+
+    # To lower case.
+    v=${v,,}
+
+    # Add dash after "rc".
+    v=${v/-rc/-rc-}
+
+    # Remove trailing ".0"
+    v=${v%.0}
+
+    # Remove trailing ".0" for release candidates.
+    v=${v/.0-rc/-rc}
+
+    f="gradle-${v}-spec.nix"
+
+    if [[ -n "$1" && "$1" != "$v" ]]
+    then
+        echo "$v SKIP (nomatch)"
+        continue
+    elif [ "$1" == "" ] && [ -f "$f" ]
+    then
+        echo "$v SKIP (exists)"
+        continue
+    fi
+
+    url="https://services.gradle.org/distributions/gradle-${v}-bin.zip"
+    read -d "\n" gradle_hash gradle_path < <(nix-prefetch-url --print-path $url)
+
+    # Prefix and suffix for "native-platform" dependency.
+    gradle_native_prefix="gradle-$v/lib/native-platform-"
+    gradle_native_suffix=".jar"
+    tmp=$(mktemp)
+    zipinfo -1 "$gradle_path" "$gradle_native_prefix*$gradle_native_suffix" > $tmp
+    gradle_native=$(cat $tmp | head -n1)
+    gradle_native=${gradle_native#"$gradle_native_prefix"}
+    gradle_native=${gradle_native%"$gradle_native_suffix"}
+
+    # Supported architectures
+    #grep -Pho "(linux|osx)-\w+" $tmp | sort | uniq
+    rm -f $tmp
+
+    echo -e "{\\n  version = \"$v\";\\n  nativeVersion = \"$gradle_native\";\\n  sha256 = \"$gradle_hash\";\\n}" > $f
+
+    echo "$v DONE"
+done