2022-03-30 09:31:56 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, maven
|
|
|
|
}:
|
|
|
|
|
|
|
|
{ src
|
2023-07-15 17:15:38 +00:00
|
|
|
, patches ? [ ]
|
2022-03-30 09:31:56 +00:00
|
|
|
, pname
|
|
|
|
, version
|
2023-07-15 17:15:38 +00:00
|
|
|
, mvnHash ? ""
|
|
|
|
, mvnFetchExtraArgs ? { }
|
2022-03-30 09:31:56 +00:00
|
|
|
, mvnParameters ? ""
|
|
|
|
, ...
|
|
|
|
} @args:
|
|
|
|
|
|
|
|
# originally extracted from dbeaver
|
|
|
|
# created to allow using maven packages in the same style as rust
|
|
|
|
|
2023-08-04 22:07:22 +00:00
|
|
|
let
|
2022-03-30 09:31:56 +00:00
|
|
|
fetchedMavenDeps = stdenv.mkDerivation ({
|
|
|
|
name = "${pname}-${version}-maven-deps";
|
2023-07-15 17:15:38 +00:00
|
|
|
inherit src patches;
|
2022-03-30 09:31:56 +00:00
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
nativeBuildInputs = [
|
2022-03-30 09:31:56 +00:00
|
|
|
maven
|
|
|
|
];
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
mvn package -Dmaven.repo.local=$out/.m2 ${mvnParameters}
|
|
|
|
'';
|
|
|
|
|
|
|
|
# keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside
|
|
|
|
installPhase = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
find $out -type f \( \
|
|
|
|
-name \*.lastUpdated \
|
|
|
|
-o -name resolver-status.properties \
|
|
|
|
-o -name _remote.repositories \) \
|
2022-03-30 09:31:56 +00:00
|
|
|
-delete
|
|
|
|
'';
|
|
|
|
|
|
|
|
# don't do any fixup
|
|
|
|
dontFixup = true;
|
2023-07-15 17:15:38 +00:00
|
|
|
outputHashAlgo = if mvnHash != "" then null else "sha256";
|
2022-03-30 09:31:56 +00:00
|
|
|
outputHashMode = "recursive";
|
|
|
|
outputHash = mvnHash;
|
|
|
|
} // mvnFetchExtraArgs);
|
2023-08-04 22:07:22 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation (builtins.removeAttrs args [ "mvnFetchExtraArgs" ] // {
|
|
|
|
inherit fetchedMavenDeps;
|
|
|
|
|
|
|
|
nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [
|
|
|
|
maven
|
|
|
|
];
|
2022-03-30 09:31:56 +00:00
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
mvnDeps=$(cp -dpR ${fetchedMavenDeps}/.m2 ./ && chmod +w -R .m2 && pwd)
|
|
|
|
mvn package --offline "-Dmaven.repo.local=$mvnDeps/.m2" ${mvnParameters}
|
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
2023-08-04 22:07:22 +00:00
|
|
|
|
|
|
|
meta = args.meta or { } // {
|
|
|
|
platforms = args.meta.platforms or maven.meta.platforms;
|
|
|
|
};
|
|
|
|
})
|