2024-01-02 11:29:13 +00:00
|
|
|
|
{ jdk11, jdk17, jdk21 }:
|
2021-12-06 16:07:01 +00:00
|
|
|
|
|
2021-08-05 21:33:18 +00:00
|
|
|
|
rec {
|
2021-12-06 16:07:01 +00:00
|
|
|
|
gen =
|
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
|
{ version, hash,
|
2022-09-22 12:36:57 +00:00
|
|
|
|
|
|
|
|
|
# The default JDK/JRE that will be used for derived Gradle packages.
|
|
|
|
|
# A current LTS version of a JDK is a good choice.
|
2024-01-02 11:29:13 +00:00
|
|
|
|
defaultJava,
|
2022-09-22 12:36:57 +00:00
|
|
|
|
|
|
|
|
|
# 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"
|
|
|
|
|
]
|
|
|
|
|
}:
|
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
|
{ lib
|
|
|
|
|
, stdenv
|
|
|
|
|
, fetchurl
|
|
|
|
|
, makeWrapper
|
|
|
|
|
, unzip
|
|
|
|
|
, ncurses5
|
|
|
|
|
, ncurses6
|
|
|
|
|
, testers
|
|
|
|
|
, runCommand
|
|
|
|
|
, writeText
|
2024-09-19 14:19:46 +00:00
|
|
|
|
, autoPatchelfHook
|
2024-04-21 15:54:59 +00:00
|
|
|
|
|
|
|
|
|
# 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 ? [ ]
|
2022-09-22 12:36:57 +00:00
|
|
|
|
}:
|
2021-12-06 16:07:01 +00:00
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
2021-12-06 16:07:01 +00:00
|
|
|
|
pname = "gradle";
|
|
|
|
|
inherit version;
|
|
|
|
|
|
|
|
|
|
src = fetchurl {
|
2024-01-02 11:29:13 +00:00
|
|
|
|
inherit hash;
|
2021-12-06 16:07:01 +00:00
|
|
|
|
url =
|
|
|
|
|
"https://services.gradle.org/distributions/gradle-${version}-bin.zip";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
dontBuild = true;
|
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
|
nativeBuildInputs = [
|
|
|
|
|
makeWrapper
|
|
|
|
|
unzip
|
2024-09-26 11:04:55 +00:00
|
|
|
|
] ++ lib.optionals stdenv.hostPlatform.isLinux [
|
2024-09-19 14:19:46 +00:00
|
|
|
|
autoPatchelfHook
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
|
java
|
|
|
|
|
stdenv.cc.cc
|
|
|
|
|
ncurses5
|
|
|
|
|
ncurses6
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
# We only need to patchelf some libs embedded in JARs.
|
|
|
|
|
dontAutoPatchelf = true;
|
2021-12-06 16:07:01 +00:00
|
|
|
|
|
|
|
|
|
installPhase = with builtins;
|
|
|
|
|
let
|
|
|
|
|
toolchain = rec {
|
2022-09-22 12:36:57 +00:00
|
|
|
|
prefix = x: "JAVA_TOOLCHAIN_NIX_${toString x}";
|
|
|
|
|
varDefs = (lib.imap0 (i: x: "${prefix i} ${x}") javaToolchains);
|
|
|
|
|
varNames = lib.imap0 (i: x: prefix i) javaToolchains;
|
2021-12-06 16:07:01 +00:00
|
|
|
|
property = " -Porg.gradle.java.installations.fromEnv='${
|
|
|
|
|
concatStringsSep "," varNames
|
|
|
|
|
}'";
|
|
|
|
|
};
|
2022-09-22 12:36:57 +00:00
|
|
|
|
varDefs = concatStringsSep "\n" (map (x: " --set ${x} \\")
|
|
|
|
|
([ "JAVA_HOME ${java}" ] ++ toolchain.varDefs));
|
2021-12-06 16:07:01 +00:00
|
|
|
|
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 \
|
2022-09-22 12:36:57 +00:00
|
|
|
|
${varDefs}
|
2021-12-06 16:07:01 +00:00
|
|
|
|
--add-flags "-classpath $gradle_launcher_jar org.gradle.launcher.GradleMain${toolchain.property}"
|
|
|
|
|
'';
|
|
|
|
|
|
2024-09-26 11:04:55 +00:00
|
|
|
|
dontFixup = !stdenv.hostPlatform.isLinux;
|
2021-12-06 16:07:01 +00:00
|
|
|
|
|
2024-09-26 11:04:55 +00:00
|
|
|
|
fixupPhase = let arch = if stdenv.hostPlatform.is64bit then "amd64" else "i386";
|
2021-12-06 16:07:01 +00:00
|
|
|
|
in ''
|
2024-09-19 14:19:46 +00:00
|
|
|
|
. ${./patching.sh}
|
|
|
|
|
|
|
|
|
|
nativeVersion="$(extractVersion native-platform $out/lib/gradle/lib/native-platform-*.jar)"
|
2021-12-26 17:43:05 +00:00
|
|
|
|
for variant in "" "-ncurses5" "-ncurses6"; do
|
2024-09-19 14:19:46 +00:00
|
|
|
|
autoPatchelfInJar \
|
|
|
|
|
$out/lib/gradle/lib/native-platform-linux-${arch}$variant-''${nativeVersion}.jar \
|
|
|
|
|
"${stdenv.cc.cc.lib}/lib64:${lib.makeLibraryPath [ stdenv.cc.cc ncurses5 ncurses6 ]}"
|
2021-12-26 17:43:05 +00:00
|
|
|
|
done
|
2021-12-06 16:07:01 +00:00
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
|
# 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 \
|
|
|
|
|
"${stdenv.cc.cc.lib}/lib64:${lib.makeLibraryPath [ stdenv.cc.cc ]}"
|
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
|
# 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
|
2021-12-26 17:43:05 +00:00
|
|
|
|
# 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
|
2020-04-24 23:36:52 +00:00
|
|
|
|
'';
|
2021-12-06 16:07:01 +00:00
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
|
passthru.tests = {
|
|
|
|
|
version = testers.testVersion {
|
|
|
|
|
package = finalAttrs.finalPackage;
|
|
|
|
|
command = ''
|
|
|
|
|
env GRADLE_USER_HOME=$TMPDIR/gradle org.gradle.native.dir=$TMPDIR/native \
|
|
|
|
|
gradle --version
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
2024-07-27 06:49:29 +00:00
|
|
|
|
passthru.jdk = defaultJava;
|
2024-04-21 15:54:59 +00:00
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
|
meta = with lib; {
|
2022-09-22 12:36:57 +00:00
|
|
|
|
inherit platforms;
|
2021-12-06 16:07:01 +00:00
|
|
|
|
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}";
|
2022-06-26 10:26:21 +00:00
|
|
|
|
sourceProvenance = with sourceTypes; [
|
|
|
|
|
binaryBytecode
|
|
|
|
|
binaryNativeCode
|
|
|
|
|
];
|
2021-12-06 16:07:01 +00:00
|
|
|
|
license = licenses.asl20;
|
2021-12-26 17:43:05 +00:00
|
|
|
|
maintainers = with maintainers; [ lorenzleutgeb liff ];
|
2023-08-22 20:05:09 +00:00
|
|
|
|
mainProgram = "gradle";
|
2021-12-06 16:07:01 +00:00
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
|
});
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2022-09-22 12:36:57 +00:00
|
|
|
|
# NOTE: Default JDKs that are hardcoded below must be LTS versions
|
|
|
|
|
# and respect the compatibility matrix at
|
2021-12-06 16:07:01 +00:00
|
|
|
|
# https://docs.gradle.org/current/userguide/compatibility.html
|
2020-07-18 16:06:22 +00:00
|
|
|
|
|
2023-04-12 12:48:02 +00:00
|
|
|
|
gradle_8 = gen {
|
2024-09-19 14:19:46 +00:00
|
|
|
|
version = "8.10";
|
|
|
|
|
hash = "sha256-W5xes/n8LJSrrqV9kL14dHyhF927+WyFnTdBGBoSvyo=";
|
2024-01-02 11:29:13 +00:00
|
|
|
|
defaultJava = jdk21;
|
2023-04-12 12:48:02 +00:00
|
|
|
|
};
|
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
|
gradle_7 = gen {
|
2024-02-29 20:09:43 +00:00
|
|
|
|
version = "7.6.4";
|
|
|
|
|
hash = "sha256-vtHaM8yg9VerE2kcd/OLtnOIEZ5HlNET4FEDm4Cvm7E=";
|
2021-12-06 16:07:01 +00:00
|
|
|
|
defaultJava = jdk17;
|
|
|
|
|
};
|
2020-07-18 16:06:22 +00:00
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
|
gradle_6 = gen {
|
2023-03-04 12:14:45 +00:00
|
|
|
|
version = "6.9.4";
|
2024-01-02 11:29:13 +00:00
|
|
|
|
hash = "sha256-PiQCKFON6fGHcqV06ZoLqVnoPW7zUQFDgazZYxeBOJo=";
|
2021-12-06 16:07:01 +00:00
|
|
|
|
defaultJava = jdk11;
|
|
|
|
|
};
|
2024-07-27 06:49:29 +00:00
|
|
|
|
|
|
|
|
|
wrapGradle = {
|
|
|
|
|
lib, callPackage, mitm-cache, substituteAll, symlinkJoin, concatTextFile, makeSetupHook
|
|
|
|
|
}:
|
|
|
|
|
gradle-unwrapped:
|
|
|
|
|
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
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
|
fetchDeps = callPackage ./fetch-deps.nix { inherit mitm-cache; };
|
|
|
|
|
inherit (gradle) jdk;
|
2024-07-31 10:19:44 +00:00
|
|
|
|
unwrapped = gradle;
|
2024-07-27 06:49:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
meta = gradle.meta // {
|
|
|
|
|
# prefer normal gradle/mitm-cache over this wrapper, this wrapper only provides the setup hook
|
|
|
|
|
# and passthru
|
2024-09-19 14:19:46 +00:00
|
|
|
|
priority = (gradle.meta.priority or lib.meta.defaultPriority) + 1;
|
2024-07-27 06:49:29 +00:00
|
|
|
|
};
|
|
|
|
|
}) { };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
}
|