diff --git a/pkgs/development/tools/build-managers/gradle/default.nix b/pkgs/development/tools/build-managers/gradle/default.nix index dbe40de5183e..8245da6875d3 100644 --- a/pkgs/development/tools/build-managers/gradle/default.nix +++ b/pkgs/development/tools/build-managers/gradle/default.nix @@ -1,9 +1,15 @@ -{ jdk11, jdk17, jdk21 }: +{ + jdk11, + jdk17, + jdk21, +}: rec { gen = - { version, hash, + { + version, + hash, # The default JDK/JRE that will be used for derived Gradle packages. # A current LTS version of a JDK is a good choice. @@ -27,28 +33,29 @@ rec { # Extra attributes to be merged into the resulting derivation's # meta attribute. - meta ? {} + meta ? { }, }: - { lib - , stdenv - , fetchurl - , makeWrapper - , unzip - , ncurses5 - , ncurses6 - , udev - , testers - , runCommand - , writeText - , autoPatchelfHook + { + lib, + stdenv, + fetchurl, + makeWrapper, + unzip, + ncurses5, + ncurses6, + udev, + testers, + runCommand, + writeText, + autoPatchelfHook, - # The JDK/JRE used for running Gradle. - , java ? defaultJava + # 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 ? [ ] + # Additional JDK/JREs to be registered as toolchains. + # See https://docs.gradle.org/current/userguide/toolchains.html + javaToolchains ? [ ], }: stdenv.mkDerivation (finalAttrs: { @@ -57,18 +64,19 @@ rec { src = fetchurl { inherit hash; - url = - "https://services.gradle.org/distributions/gradle-${version}-bin.zip"; + url = "https://services.gradle.org/distributions/gradle-${version}-bin.zip"; }; dontBuild = true; - nativeBuildInputs = [ - makeWrapper - unzip - ] ++ lib.optionals stdenv.hostPlatform.isLinux [ - autoPatchelfHook - ]; + nativeBuildInputs = + [ + makeWrapper + unzip + ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ + autoPatchelfHook + ]; buildInputs = [ java @@ -80,20 +88,21 @@ rec { # We only need to patchelf some libs embedded in JARs. dontAutoPatchelf = true; - installPhase = with builtins; + installPhase = + with builtins; let toolchain = rec { prefix = x: "JAVA_TOOLCHAIN_NIX_${toString x}"; - varDefs = (lib.imap0 (i: x: "${prefix i} ${x}") javaToolchains); + 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 - }'"; + property = " -Porg.gradle.java.installations.fromEnv='${concatStringsSep "," varNames}'"; }; - varDefs = concatStringsSep "\n" (map (x: " --set ${x} \\") - ([ "JAVA_HOME ${java}" ] ++ toolchain.varDefs)); + varDefs = concatStringsSep "\n" ( + map (x: " --set ${x} \\") ([ "JAVA_HOME ${java}" ] ++ toolchain.varDefs) + ); jnaLibraryPath = lib.makeLibraryPath [ udev ]; - in '' + in + '' mkdir -pv $out/lib/gradle/ cp -rv lib/ $out/lib/gradle/ @@ -107,33 +116,42 @@ rec { dontFixup = !stdenv.hostPlatform.isLinux; - fixupPhase = let arch = if stdenv.hostPlatform.is64bit then "amd64" else "i386"; - in '' - . ${./patching.sh} + fixupPhase = + let + arch = if stdenv.hostPlatform.is64bit then "amd64" else "i386"; + in + '' + . ${./patching.sh} - nativeVersion="$(extractVersion native-platform $out/lib/gradle/lib/native-platform-*.jar)" - for variant in "" "-ncurses5" "-ncurses6"; do + nativeVersion="$(extractVersion native-platform $out/lib/gradle/lib/native-platform-*.jar)" + for variant in "" "-ncurses5" "-ncurses6"; do + autoPatchelfInJar \ + $out/lib/gradle/lib/native-platform-linux-${arch}$variant-''${nativeVersion}.jar \ + "${lib.getLib stdenv.cc.cc}/lib64:${ + lib.makeLibraryPath [ + stdenv.cc.cc + ncurses5 + ncurses6 + ] + }" + done + + # The file-events library _seems_ to follow the native-platform version, but + # we won’t assume that. + fileEventsVersion="$(extractVersion file-events $out/lib/gradle/lib/file-events-*.jar)" autoPatchelfInJar \ - $out/lib/gradle/lib/native-platform-linux-${arch}$variant-''${nativeVersion}.jar \ - "${lib.getLib stdenv.cc.cc}/lib64:${lib.makeLibraryPath [ stdenv.cc.cc ncurses5 ncurses6 ]}" - done + $out/lib/gradle/lib/file-events-linux-${arch}-''${fileEventsVersion}.jar \ + "${lib.getLib stdenv.cc.cc}/lib64:${lib.makeLibraryPath [ stdenv.cc.cc ]}" - # The file-events library _seems_ to follow the native-platform version, but - # we won’t assume that. - fileEventsVersion="$(extractVersion file-events $out/lib/gradle/lib/file-events-*.jar)" - autoPatchelfInJar \ - $out/lib/gradle/lib/file-events-linux-${arch}-''${fileEventsVersion}.jar \ - "${lib.getLib stdenv.cc.cc}/lib64:${lib.makeLibraryPath [ stdenv.cc.cc ]}" - - # 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 - echo ${udev} >> $out/nix-support/manual-runtime-dependencies - ''; + # 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 + echo ${udev} >> $out/nix-support/manual-runtime-dependencies + ''; passthru.tests = { version = testers.testVersion { @@ -147,40 +165,53 @@ rec { java-application = testers.testEqualContents { assertion = "can build and run a trivial Java application"; expected = writeText "expected" "hello\n"; - actual = runCommand "actual" { - nativeBuildInputs = [ finalAttrs.finalPackage ]; - src = ./tests/java-application; - } '' - cp -a $src/* . - env GRADLE_USER_HOME=$TMPDIR/gradle org.gradle.native.dir=$TMPDIR/native \ - gradle run --no-daemon --quiet --console plain > $out - ''; + actual = + runCommand "actual" + { + nativeBuildInputs = [ finalAttrs.finalPackage ]; + src = ./tests/java-application; + } + '' + cp -a $src/* . + env GRADLE_USER_HOME=$TMPDIR/gradle org.gradle.native.dir=$TMPDIR/native \ + gradle run --no-daemon --quiet --console plain > $out + ''; }; }; passthru.jdk = defaultJava; - 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; [ britter liff lorenzleutgeb ] ++ lib.teams.java.members; - mainProgram = "gradle"; - } // meta; + 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; + [ + britter + liff + lorenzleutgeb + ] + ++ lib.teams.java.members; + mainProgram = "gradle"; + } + // meta; }); # NOTE: Default JDKs that are hardcoded below must be LTS versions @@ -199,49 +230,61 @@ rec { defaultJava = jdk17; }; - wrapGradle = { - lib, callPackage, mitm-cache, substituteAll, symlinkJoin, concatTextFile, makeSetupHook, nix-update-script + wrapGradle = + { + lib, + callPackage, + mitm-cache, + substituteAll, + symlinkJoin, + concatTextFile, + makeSetupHook, + nix-update-script, }: - gradle-unwrapped: - updateAttrPath: - lib.makeOverridable (args: - let - gradle = gradle-unwrapped.override args; - in symlinkJoin { - name = "gradle-${gradle.version}"; + gradle-unwrapped: updateAttrPath: + lib.makeOverridable ( + args: + let + gradle = gradle-unwrapped.override args; + in + symlinkJoin { + name = "gradle-${gradle.version}"; - paths = [ - (makeSetupHook { name = "gradle-setup-hook"; } (concatTextFile { - name = "setup-hook.sh"; - files = [ - (mitm-cache.setupHook) - (substituteAll { - src = ./setup-hook.sh; - # jdk used for keytool - inherit (gradle) jdk; - init_script = ./init-build.gradle; - }) - ]; - })) - gradle - mitm-cache - ]; + paths = [ + (makeSetupHook { name = "gradle-setup-hook"; } (concatTextFile { + name = "setup-hook.sh"; + files = [ + (mitm-cache.setupHook) + (substituteAll { + src = ./setup-hook.sh; + # jdk used for keytool + inherit (gradle) jdk; + init_script = ./init-build.gradle; + }) + ]; + })) + gradle + mitm-cache + ]; - passthru = { - fetchDeps = callPackage ./fetch-deps.nix { inherit mitm-cache; }; - inherit (gradle) jdk tests; - unwrapped = gradle; - } // lib.optionalAttrs (updateAttrPath != null) { - updateScript = nix-update-script { - attrPath = updateAttrPath; - extraArgs = [ "--url=https://github.com/gradle/gradle" ]; + passthru = + { + fetchDeps = callPackage ./fetch-deps.nix { inherit mitm-cache; }; + inherit (gradle) jdk tests; + unwrapped = gradle; + } + // lib.optionalAttrs (updateAttrPath != null) { + updateScript = nix-update-script { + attrPath = updateAttrPath; + extraArgs = [ "--url=https://github.com/gradle/gradle" ]; + }; + }; + + meta = gradle.meta // { + # prefer normal gradle/mitm-cache over this wrapper, this wrapper only provides the setup hook + # and passthru + priority = (gradle.meta.priority or lib.meta.defaultPriority) + 1; }; - }; - - meta = gradle.meta // { - # prefer normal gradle/mitm-cache over this wrapper, this wrapper only provides the setup hook - # and passthru - priority = (gradle.meta.priority or lib.meta.defaultPriority) + 1; - }; - }) { }; + } + ) { }; }