# This file is generated by gradle2nix. # # Example usage (e.g. in default.nix): # # with (import {}); # let # buildGradle = callPackage ./gradleEnv.nix {}; # in # buildGradle { # envSpec = ./gradle-env.json; # # src = ./.; # # gradleFlags = [ "installDist" ]; # # installPhase = '' # mkdir -p $out # cp -r app/build/install/myproject $out # ''; # } { stdenv, lib, buildEnv, fetchurl, gradleGen, writeText }: { envSpec , pname ? null , version ? null , enableParallelBuilding ? true , gradleFlags ? [ "build" ] , gradlePackage ? null , ... } @ args: let mkDep = depSpec: stdenv.mkDerivation { inherit (depSpec) name; src = fetchurl { inherit (depSpec) urls sha256; }; phases = "installPhase"; installPhase = '' mkdir -p $out/${depSpec.path} ln -s $src $out/${depSpec.path}/${depSpec.filename} ''; }; mkRepo = project: type: deps: buildEnv { name = "${project}-gradle-${type}-env"; paths = map mkDep deps; }; mkInitScript = projectSpec: let repos = builtins.mapAttrs (mkRepo projectSpec.name) projectSpec.dependencies; in writeText "init.gradle" '' gradle.settingsEvaluated { it.pluginManagement.repositories { clear() maven { url = uri("${repos.plugin}") } } } gradle.projectsLoaded { allprojects { buildscript { repositories { clear() maven { url = uri("${repos.buildscript}") } } } repositories { clear() maven { url = uri("${repos.project}") } } } } ''; mkGradle = gradleSpec: gradleGen.gradleGen { inherit (gradleSpec) nativeVersion; name = "gradle-${gradleSpec.version}-${gradleSpec.type}"; src = fetchurl { inherit (gradleSpec) url sha256; }; }; mkProjectEnv = projectSpec: { inherit (projectSpec) name version; initScript = mkInitScript projectSpec; gradle = args.gradlePackage or mkGradle projectSpec.gradle; }; gradleEnv = builtins.mapAttrs (_: p: mkProjectEnv p) (builtins.fromJSON (builtins.readFile envSpec)); projectEnv = gradleEnv.""; pname = args.pname or projectEnv.name; version = args.version or projectEnv.version; in stdenv.mkDerivation (args // { inherit pname version; nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ projectEnv.gradle ]; buildPhase = args.buildPhase or '' runHook preBuild ( set -x env \ "GRADLE_USER_HOME=$(mktemp -d)" \ gradle --offline --no-daemon --no-build-cache \ --info --full-stacktrace --warning-mode=all \ ${lib.optionalString enableParallelBuilding "--parallel"} \ --init-script ${projectEnv.initScript} \ ${builtins.concatStringsSep " " gradleFlags} ) runHook postBuild ''; dontStrip = true; })